1- // datatypes.js
2-
31/*
2+ INFO: DataTypes
43JavaScript is dynamically typed, so variables can hold any type of data without explicit type declaration.
54
65Common data types in JavaScript:
@@ -19,7 +18,7 @@ Common data types in JavaScript:
1918
2019// String
2120let name = "whoami" ;
22- console . log ( name ) ; // whoami
21+ console . log ( name ) ; // " whoami"
2322
2423// Number
2524let score = 102 ;
@@ -29,22 +28,40 @@ console.log(score); // 102
2928let isLoggedIn = false ;
3029console . log ( isLoggedIn ) ; // false
3130
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
3344let teaTypes = [ "lemon tea" , "orange tea" , "oolong tea" ] ;
3445console . log ( teaTypes ) ; // ["lemon tea", "orange tea", "oolong tea"]
3546
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+ } ;
3852console . log ( user ) ; // { firstName: "whoami", lastName: "dsnake0" }
3953
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)
4357
44- // Undefined example
45- let something ;
46- console . log ( something ) ; // undefined
58+ // INFO: Type of each DataTypes
4759
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