|
| 1 | +# JavaScript Data Types 📚 |
1 | 2 |
|
| 3 | +It defines the What kind of data that a variable can hold. |
| 4 | + |
| 5 | +JavaScript supports various data types, which can be classified into primitive and non-primitive types. |
| 6 | +1. Primitive Data Types |
| 7 | +- These are the most basic data types in JavaScript. |
| 8 | +- They are immutable (cannot be changed). |
| 9 | +- They are passed by value. |
| 10 | + |
| 11 | +2. NonPrimitive Data Types |
| 12 | +- These are more complex data types. |
| 13 | +- They are mutable (can be changed). |
| 14 | +- They are passed by reference. |
| 15 | + |
| 16 | +Here's an overview: 👇 |
| 17 | + |
| 18 | +## Primitive Data Types |
| 19 | + |
| 20 | +| Data Type | Description | Example | |
| 21 | +|------------|---------------------------------------------------|-------------------| |
| 22 | +| Number | Represents numeric values | `let num = 42;` | |
| 23 | +| String | Represents sequences of characters | `let str = "Hello";` | |
| 24 | +| Boolean | Represents a logical value (true or false) | `let bool = true;` | |
| 25 | +| Undefined | Represents a variable that hasn't been assigned a value | `let undef;` | |
| 26 | +| Null | Represents the intentional absence of any value | `let nul = null;` | |
| 27 | + |
| 28 | +## Non-Primitive Data Types |
| 29 | + |
| 30 | +| Data Type | Description | Example | |
| 31 | +|------------|---------------------------------------------------|---------------------------------| |
| 32 | +| Object | Represents a collection of key-value pairs | `let obj = { key: "value" };` | |
| 33 | +| Function | A special type of object that is callable | `function func() {}` | |
| 34 | + |
| 35 | +## Other Data Types |
| 36 | + |
| 37 | +JavaScript also has other data types, such as `Symbol` and `BigInt`, which are less commonly used in everyday programming tasks. |
| 38 | + |
| 39 | +## Usage of `typeof` |
| 40 | + |
| 41 | +You can use the `typeof` operator to determine the data type of a value or variable: |
| 42 | + |
| 43 | +`Example` |
| 44 | + |
| 45 | +```javascript |
| 46 | +let num = 42; |
| 47 | +console.log(typeof num); // Output: "number" |
| 48 | +``` |
0 commit comments