Data types in JavaScript
testYourself
JavaScript1214
In JavaScript, there are a few primitive data types. Primitive data type is not an object and has no methods or properties.
In JavaScript, you can declare variables of any type using the var, let, and const keywords. There are no dedicated keywords for specific data types.
Number
It doesn't matter whether it's a floating point number or an integer, JavaScript only has one data type for numeric values - number.
console.log(typeof 5); // number
console.log(typeof 5.3); // number
console.log(typeof -5); // number
Boolean
The boolean is a logical data type that can only store true or false values.
console.log(typeof true); // boolean
console.log(typeof false); // boolean
String
The string is a sequence of characters that is used to represent text.
console.log(typeof "abc"); // string
console.log(typeof 'c'); // string
console.log(typeof "11.1"); // string
Undefined
An undefined value is a primitive value automatically assigned to variables that have just been declared but not yet initialized.
console.log(typeof undefined); // undefined
Null
The null value represents the intentional absence of any value.
console.log(typeof null); // 'object'