|
1 | | -// In javascript we do not need to specify type of the varialbe because if is dynamically used by javascript engine. We can use var data type. It can hold any type of data like String, Number, Boolen etc. |
| 1 | +// datatypes.js |
2 | 2 |
|
3 | | -console.log("hello"); |
4 | | -// console.log("cai"); |
5 | 3 | /* |
| 4 | +JavaScript is dynamically typed, so variables can hold any type of data without explicit type declaration. |
6 | 5 |
|
7 | | -String |
8 | | -Number |
9 | | -Boolean |
10 | | -Bigint |
11 | | -Undefined |
12 | | -null |
13 | | -Object |
14 | | -Symbol |
| 6 | +Common data types in JavaScript: |
15 | 7 |
|
| 8 | +1. String - Text wrapped in quotes |
| 9 | +2. Number - Numeric values (integers and floats) |
| 10 | +3. Boolean - true or false |
| 11 | +4. BigInt - For very large integers |
| 12 | +5. Undefined - A variable declared but not assigned a value |
| 13 | +6. Null - Represents intentional absence of any object value |
| 14 | +7. Object - Collections of key-value pairs, arrays, functions, etc. |
| 15 | +8. Symbol - Unique and immutable primitive values |
16 | 16 | */ |
17 | 17 |
|
18 | | -// var score = 102; |
| 18 | +// Examples of different data types: |
19 | 19 |
|
20 | | -let score = 102; |
| 20 | +// String |
21 | 21 | let name = "whoami"; |
22 | | -let isLoggedin = false; |
| 22 | +console.log(name); // whoami |
| 23 | + |
| 24 | +// Number |
| 25 | +let score = 102; |
| 26 | +console.log(score); // 102 |
| 27 | + |
| 28 | +// Boolean |
| 29 | +let isLoggedIn = false; |
| 30 | +console.log(isLoggedIn); // false |
23 | 31 |
|
24 | | -// object |
| 32 | +// Object - Array |
25 | 33 | let teaTypes = ["lemon tea", "orange tea", "oolong tea"]; |
26 | | -let user = { firstname: "whoami", lastname: "dsnake0" } |
| 34 | +console.log(teaTypes); // ["lemon tea", "orange tea", "oolong tea"] |
27 | 35 |
|
| 36 | +// Object - Plain Object |
| 37 | +let user = { firstName: "whoami", lastName: "dsnake0" }; |
| 38 | +console.log(user); // { firstName: "whoami", lastName: "dsnake0" } |
| 39 | + |
| 40 | +// Assigning variable values |
28 | 41 | let getScore = score; |
29 | | -console.log(getScore) |
| 42 | +console.log(getScore); // 102 |
| 43 | + |
| 44 | +// Undefined example |
| 45 | +let something; |
| 46 | +console.log(something); // undefined |
| 47 | + |
| 48 | +// Null example |
| 49 | +let emptyValue = null; |
| 50 | +console.log(emptyValue); // null |
0 commit comments