-
Notifications
You must be signed in to change notification settings - Fork 0
/
file130.js
50 lines (37 loc) · 1.45 KB
/
file130.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
"use strict";
// synchronous programming vs asynchrous programming
// synchronous programming
// synchronous programming is single thread means code will execute one by one line
// for example
// console.log("script start");
// for(let i = 0; i<1000; i++){
// console.log("loop is running");
// }
// console.log("script End");
// asyncprogramming
// javaScript is a synchronous programming but web Api browsers gives us Asynchronous feature
// it means it will do the next task and the feature that we want to asynchronous in code will be executed in last
// let's see
// setTimeout :- file will execute after the time we had given in setTimeout and in setTimeout 1000 = 1 sec
const firstLine = setTimeout(()=>{
console.log("start printing after 5 seconds")}
,5000);
console.log("script start");
function hello(){
console.log("hello boys and girls");
}
// set setTimeout gives us id value let's calculate
const idHello = setTimeout(hello,1000);
const idInside = setTimeout(()=>{
console.log("inside set time OUt");
},0);
for(let i = 0; i<1000; i++){
console.log("loop is running");
}
console.log("script end");
console.log("id value of hello",idHello);
console.log("id value of inside",idInside);
// here we can also clear the timeline data
// i will clear inside set time out
clearTimeout(idHello);
// using cleartime out property i can clear the data withpot priniting