Datatypes are the type of data a variable can store
- Primitive types
- Reference types
| Type | description | Example |
|---|---|---|
| Number | Both integers and floating-point numbers (Number literal) | 5, 5.55, Infinity, NaN |
| String | Textual data wrapped in quotes (String literal) | "Hi", 'Hi', `Hi` |
| Boolean | Logical values: true or false | true, false |
| Undefined | A variable that has been declared but not assigned | undefined |
| Null | An intentional absence | null |
let age = 15;
let name = "Rohan";
let isAdult = false;
let Lisence = undefined; // When it is not needed when empty
let favMovie = null; // When it is needed even when emptyJS is a dynamic language i.e., the type of the variable can change during runtime.
let data = 42; // data is a Number
data = "Forty-two"; // data is now a String
data = true; // data is now a Boolean| Type | description | Example |
|---|---|---|
| Object | A collection of properties | { name: "John", age: 30 } |
| Array | A list of values | [1,2,3] |
| Function | A block of code |
previous