-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (48 loc) · 1.28 KB
/
script.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
// JavaScript is a single threaded language that can be non-blocking
//chrome has v8 javaScript engine. it has two parts viz. memory heap and call stack
//memory leak- unused memory
const a = 1;
const b = 10;
const c = 100;
//Global variables are bad because they remain in memory even if they aren't used
//call stack(synchronous task- line-10 will get exceuted first, then line-11 and then line-12)
console.log('1');
console.log('2');
console.log('3');
const one = () => {
const two = () => {
console.log(4);
}
two();
}
//call stack is first-in-last-out
//Issues with multithreaded language is they have deadlocks
//Recursion
function foo() {
foo()
}
foo()
//In javaScript non-blocking- Asynchronous behavior- can be obtainesd as below
console.log('1');
setTimeout(() => {
console.log('2');
}, 2000)
console.log('3');
//setTimeout set to 0 sec
console.log('1');
setTimeout(() => {
console.log('2');
}, 0)
console.log('3');
//javaScript runtime environment consists of the following
//1. javaScript engine (memory heap and call stack)
//2. web API's (DOM(document), AJAX(XML HTTP request), Timeout(setTimeout))
//3. callback Queue (onClick, onLoad, onDone)
//4. Event Loop
//call stack
//web APIs
//callback Queue
//Event Loop
element.addEventListener('click', () => {
console.log('click')
})