4
4
console . log ( 'Hello, World!' ) ;
5
5
6
6
// variables
7
- var num = 1 ; // {1}
8
- num = 3 ; // {2}
7
+ var num = 1 ;
8
+ num = 'one' ;
9
9
10
- let myVar = 2 ; // {3}
11
- myVar = 4 ; // {4}
10
+ let myVar = 2 ;
11
+ myVar = 4 ;
12
12
13
- const price = 1.5 ; // {5} number
14
- const publisher = 'Packt' ; // {6} string
15
- const javaScriptBook = true ; // {7} boolean
16
- const nullVar = null ; // {8} null
17
- let und ; // {9} undefined
13
+ const price = 1.5 ; // number
14
+ const publisher = 'Packt' ; // string
15
+ const javaScriptBook = true ; // boolean
16
+ const nullVar = null ; // null
17
+ let und ; // undefined
18
18
19
- console . log ( 'num: ' + num ) ;
20
- console . log ( 'myVar: ' + myVar ) ;
19
+ console . log ( 'price: ' + price ) ;
21
20
console . log ( 'publisher: ' + publisher ) ;
22
21
console . log ( 'javaScriptBook: ' + javaScriptBook ) ;
23
- console . log ( 'price: ' + price ) ;
24
22
console . log ( 'nullVar: ' + nullVar ) ;
25
23
console . log ( 'und: ' + und ) ;
26
24
25
+ console . log ( '**** Data types ****' ) ;
26
+
27
+ console . log ( 'typeof price: ' , typeof price ) ; // number
28
+ console . log ( 'typeof publisher: ' , typeof publisher ) ; // string
29
+ console . log ( 'typeof javaScriptBook: ' , typeof javaScriptBook ) ; // boolean
30
+ console . log ( 'typeof nullVar: ' , typeof nullVar ) ; // object
31
+ console . log ( 'typeof und: ' , typeof und ) ; // undefined
32
+
27
33
const book = {
28
- title : 'Data Structures and Algorithms' , // {10}
34
+ title : 'Data Structures and Algorithms' ,
29
35
}
30
- book . title = 'Data Structures and Algorithms in JavaScript' ; // {11}
31
- // book = { anotherTitle: 'Data Structures’ } // this will not work {12}
36
+
37
+ console . log ( 'book title: ' , book . title ) ;
38
+
39
+ book . title = 'Data Structures and Algorithms in JavaScript' ;
40
+ // book = { anotherTitle: 'Data Structures’ } // this will not work
41
+
42
+ // reassignment of objects:
43
+ let book2 = {
44
+ title : 'Data Structures and Algorithms' ,
45
+ }
46
+ book2 = { title : 'Data Structures' } ;
47
+
48
+ // symbol
49
+ const title = Symbol ( 'title' ) ;
50
+ const book3 = {
51
+ [ title ] : 'Data Structures and Algorithms'
52
+ } ;
53
+ console . log ( book3 [ title ] ) ; // Data Structures and Algorithms
32
54
33
55
// to see the output of this file use the command: node src/01-intro/01-hello-variables.js
0 commit comments