Javascript Primitive data types
JavaScript has six primitive data types, which are:
Number:
It represents numeric values. It can be an integer or a floating-point number. It is declared using the keyword number.
Example:
let num = 10;
let pi = 3.14;
String:
It represents a sequence of characters. It is declared using single quotes (‘) or double quotes (“).
Example:
let name = 'John';
let message = "Hello, World!";
Boolean:
It represents a logical value of true or false. It is declared using the keywords true or false.
Example:
let isCorrect = true;
let isWrong = false;
Null:
It represents the intentional absence of any object value. It is declared using the keyword null.
Example:
let value = null;
Output:
Undefined:
It represents the absence of a defined value. It is declared using the keyword undefined.
Example:
let num;
console.log(num); // output: undefined
Symbol:
It represents a unique identifier. It is declared using the keyword symbol.
Example:
let sym1 = Symbol();
let sym2 = Symbol('foo');