-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (67 loc) · 1.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Variable scope n hoisting
* Function hoisting
*
* Before ES6:
* Variables define by 'var' are only have function scope
* Variables define by 'var' are hoisted to the top of scope
* ES6: let + const have block-statement scope n doesn't hoist varibles
*
* Only func declaration gets hoisted
*/
;(function() {
console.log(x) // => undefined
if (true) {
var x = 10
let y = 20
}
console.log(x) // => 10
// console.log(y) // => Reference Error
var foo = 10
;(function() {
console.log(foo) // => undefined (because of hoisting)
var foo = 20
})
// console.log(bar) // => Reference Error
let bar = 'bar'
// Function declaration
fu() // => 'fu'
function fu() { console.log('fu') }
// Function expression (!) an expr always have a '='
// baz() // => Reference Error
var baz = function() { console.log('baz') }
})
/**
* Data types (JS have 7 types: 6 primitives + Object)
* Primite type is not obj n its doesn't have methods
* They are: null, undefined, Number, String, Boolean n Symbol ??
* 6 falsy values: false, 0, undefined, null, "", NaN
*/
/**
* A Promise is in one of these 4 states:
* - Pending
* - Fulfilled
* - Rejected
* - Settled: either fulfilled of rejected but not pending
*/
/**
* == check the equalty with coercion allowed
* === check the equalty without allowing coercion
*
* In case of comparing 2 non-premitive values (obj include array n func)
* both == n === will simply check whether the refs match, not any thing about the underlying values
*/
;(function() {
// This is anonymous function (a func that assigned to a variable n it has no name)
let foo = function() { console.log('Foooo') }
foo()
// The default argument
function multiply(a, b = 2) { console.log(a * b) }
multiply(10)
multiply(10, 3)
// Arrow function does not have its own 'this', '...args' n super
const bar = function() { console.log('bar', this) }
// bar()
const arrowBar = () => console.log('arrowBar', this)
arrowBar()
})()