The String Data Type
The string data type represents a sequence of characters enclosed within single quotes (”) or double quotes (“”). For example:
Strings are commonly used to store text-based information such as names, messages, or even entire HTML code snippets.
The Number Data Type
The number data type represents numeric values. Numbers can be either integers or floating-point numbers (decimals).
0.5e-3 (scientific notation)
Numbers are used for mathematical calculations and storing numerical data.
The Boolean Data Type
The boolean data type represents logical values. It can only have two possible values: true or false.
Booleans are often used in conditional statements and logical operations.
The Null Data Type
The null data type represents the absence of any object value. It is a special value that indicates the intentional absence of an object reference.
Null is commonly used to initialize variables or indicate that a variable does not currently have a value.
The Undefined Data Type
The undefined data type is used when a variable has been declared but has not been assigned a value. In other words, it indicates the absence of any meaningful value.
console.log(x); // undefined
Undefined is often encountered when accessing properties or variables that do not exist.
The Symbol Data Type (Exception)
Symbols are created using the
Symbol() constructor function or by calling the static method
Symbol.for(). Unlike other primitive data types, symbols are not implicitly convertible to other types.