1. Boolean: Represents either true or false. 2. Number: Represents numeric values. 3. String: Represents textual data enclosed within single quotes (”) or double quotes (“”).
4. Null: Represents the intentional absence of any object value. 5. Undefined: Represents the absence of a defined value. 6. Symbol: Introduced in ECMAScript 6, symbols are unique and immutable values that can be used as property keys.
The Answer: NaN (Not-a-Number)
To check if a value is NaN, you can use the isNaN() function:
const result = isNaN(‘Hello’); // true
In the above example, ‘Hello’ is not a number, so isNaN() returns true.
Common Data Type Mistakes:
1. Using a string instead of a number:
const result = ’10’ + 5;
console.log(result); // “105”
In the above example, the string ’10’ is concatenated with the number 5, resulting in the string ‘105’. To perform arithmetic operations, make sure to convert the string to a number using parseInt() or parseFloat().
2. Forgetting to use parentheses:
const result = 10 * 2 + 3;
console.log(result); // 23