File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
part2 (Data Types and Primitives) Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ // Primitive Data Types in JavaScript
2+ // These are the most basic data types — stored directly by value (not by reference).
3+
4+ // 1. Number
5+ let age = 25 ; // Integer
6+ let pi = 3.14 ; // Float
7+
8+ console . log ( typeof age ) ; // "number"
9+ console . log ( typeof pi ) ; // "number"
10+
11+ // 2. String
12+ let name = "Rafay" ;
13+ let greeting = `Hello, ${ name } !` ; // Template string (string interpolation)
14+
15+ console . log ( typeof name ) ; // "string"
16+ console . log ( greeting ) ; // "Hello, Rafay!"
17+
18+ // 3. Boolean
19+ let isOnline = true ;
20+ let isAdmin = false ;
21+
22+ console . log ( typeof isOnline ) ; // "boolean"
23+
24+ // 4. Null
25+ let emptyValue = null ;
26+
27+ console . log ( typeof emptyValue ) ; // "object" (⚠️ a known JavaScript quirk)
28+
29+ // 5. Undefined
30+ let notAssigned ;
31+
32+ console . log ( typeof notAssigned ) ; // "undefined"
33+
34+ // 6. BigInt
35+ let bigNumber = 1234567890123456789012345678901234567890n ; // Add 'n' at the end
36+
37+ console . log ( typeof bigNumber ) ; // "bigint"
38+
39+ // 7. Symbol
40+ let uniqueId1 = Symbol ( "userId" ) ;
41+ let uniqueId2 = Symbol ( "userId" ) ;
42+
43+ console . log ( typeof uniqueId1 ) ; // "symbol"
44+ console . log ( uniqueId1 === uniqueId2 ) ; // false – every Symbol is unique!
You can’t perform that action at this time.
0 commit comments