-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiife.js
51 lines (36 loc) · 776 Bytes
/
iife.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
/* immediately invoked function expression */
//it can pass to any other variable.
//anything inside it has its own scope.
//can be used with anonymous function.
//Syntax:-
/*
(function(){
//body
})();
*/
(function(){
})()
//Example
//declare anonymous function
/*
let str="iife";
const f =(function(){
//let str="iife";
return str;
})();
//call function
console.log(f);
*/
//Example
/*
//iife using closure
const f=(function(){
let count = 1;
return function(){
return `value of count:${count++}`;
}
})();
console.log(f());
console.log(f());
console.log(f());
*/