JavaScript: Primitive Data Types Flashcards
What are the five main primitive data types?
Primitive data types include (1) undefined, (2) string, (3) number, (4) boolean and (5) null
Undefined
Undefined variables haven’t been assigned values yet.
let myUndefined;
String
A string is a series of characters and is surrounded by quotes .
const myStringWelcome = “Hello World”;
const myStringPassword = “865Password!2020”;
Number
A number can be either an integer or a decimal.
const myNumberInt = 100;
const myNumberDecimal = 100.100;
Booleans
Booleans have two values: true or false.
const isMyBooleanTrue = true;
const isMyBooleanFalse = false;
Null
Null is both a value and type. It represents the concept of nothing. This differs from undefined, which is an unknown value. Null is known to be nothing.
const myNull = null;
How do you check the type of data?
To check the type of data, use typeof followed by the name of the variable.
console.log(typeof myUndefined);