44console . log ( 'Hello, World!' ) ;
55
66// variables
7- var num = 1 ; // {1}
8- num = 3 ; // {2}
7+ var num = 1 ;
8+ num = 'one' ;
99
10- let myVar = 2 ; // {3}
11- myVar = 4 ; // {4}
10+ let myVar = 2 ;
11+ myVar = 4 ;
1212
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
1818
19- console . log ( 'num: ' + num ) ;
20- console . log ( 'myVar: ' + myVar ) ;
19+ console . log ( 'price: ' + price ) ;
2120console . log ( 'publisher: ' + publisher ) ;
2221console . log ( 'javaScriptBook: ' + javaScriptBook ) ;
23- console . log ( 'price: ' + price ) ;
2422console . log ( 'nullVar: ' + nullVar ) ;
2523console . log ( 'und: ' + und ) ;
2624
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+
2733const book = {
28- title : 'Data Structures and Algorithms' , // {10}
34+ title : 'Data Structures and Algorithms' ,
2935}
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
3254
3355// to see the output of this file use the command: node src/01-intro/01-hello-variables.js
0 commit comments