Skip to content

Commit f7989d3

Browse files
committed
Learned about IIFE, named and simple IIFE, how to pass parameter, arguments in a IIFE function & how to write two iife in the same file.
1 parent 1c1e996 commit f7989d3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

03_Basics/06_iife.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* 6. IIFE (Immediately Invoked Function Expressions)
2+
3+
Note: An IIFE in JavaScript is a function that is executed immediately
4+
after it's defined. It's typically used to create a private scope for variables
5+
and functions to avoid polluting the global namespace.
6+
7+
Name IIFE, */
8+
(function chai(){
9+
console.log(`DB Connected`);
10+
})(); /* Output: DB Connected
11+
Note: Using semicolon ; to end the first IIFE function.
12+
13+
Simple IIFE, */
14+
((name) /* parameter */ => {
15+
console.log(`DB Connected, ${name}`);
16+
})("Ayush") // argument | Output: DB Connected, Ayush

0 commit comments

Comments
 (0)