1
- // datatypes.js
2
-
3
1
/*
2
+ INFO: DataTypes
4
3
JavaScript is dynamically typed, so variables can hold any type of data without explicit type declaration.
5
4
6
5
Common data types in JavaScript:
@@ -19,7 +18,7 @@ Common data types in JavaScript:
19
18
20
19
// String
21
20
let name = "whoami" ;
22
- console . log ( name ) ; // whoami
21
+ console . log ( name ) ; // " whoami"
23
22
24
23
// Number
25
24
let score = 102 ;
@@ -29,22 +28,40 @@ console.log(score); // 102
29
28
let isLoggedIn = false ;
30
29
console . log ( isLoggedIn ) ; // false
31
30
32
- // Object - Array
31
+ // BigInt (used for very large integers beyond Number limit)
32
+ let largeNumber = 1234567890123456789012345678901234567890n ;
33
+ console . log ( largeNumber ) ; // 1234567890123456789012345678901234567890n
34
+
35
+ // Undefined (a variable declared but not assigned a value)
36
+ let something ;
37
+ console . log ( something ) ; // undefined
38
+
39
+ // Null (represents an intentional empty value)
40
+ let emptyValue = null ;
41
+ console . log ( emptyValue ) ; // null
42
+
43
+ // Object – Array
33
44
let teaTypes = [ "lemon tea" , "orange tea" , "oolong tea" ] ;
34
45
console . log ( teaTypes ) ; // ["lemon tea", "orange tea", "oolong tea"]
35
46
36
- // Object - Plain Object
37
- let user = { firstName : "whoami" , lastName : "dsnake0" } ;
47
+ // Object – Plain Object
48
+ let user = {
49
+ firstName : "whoami" ,
50
+ lastName : "dsnake0" ,
51
+ } ;
38
52
console . log ( user ) ; // { firstName: "whoami", lastName: "dsnake0" }
39
53
40
- // Assigning variable values
41
- let getScore = score ;
42
- console . log ( getScore ) ; // 102
54
+ // Symbol (used to create unique identifiers)
55
+ let uniqueId = Symbol ( "id" ) ;
56
+ console . log ( uniqueId ) ; // Symbol(id)
43
57
44
- // Undefined example
45
- let something ;
46
- console . log ( something ) ; // undefined
58
+ // INFO: Type of each DataTypes
47
59
48
- // Null example
49
- let emptyValue = null ;
50
- console . log ( emptyValue ) ; // null
60
+ console . log ( typeof name ) ; // "string"
61
+ console . log ( typeof score ) ; // "number"
62
+ console . log ( typeof isLoggedIn ) ; // "boolean"
63
+ console . log ( typeof largeNumber ) ; // "bigint"
64
+ console . log ( typeof something ) ; // "undefined"
65
+ console . log ( typeof emptyValue ) ; // "object" (this is a historical JS bug)
66
+ console . log ( typeof teaTypes ) ; // "object"
67
+ console . log ( typeof uniqueId ) ; // "symbol"
0 commit comments