There was an error while loading. Please reload this page.
1 parent b61b4af commit f0a01c5Copy full SHA for f0a01c5
part5 (Functions)/AdvanceFunctions/06_four.ways.to.write.function.js
@@ -0,0 +1,32 @@
1
+// INFO: Four ways to write function
2
+
3
+/*
4
+NOTE: Why this matters ?
5
+JavaScrpit allows multiple ways to define fucntions, and each has different behaviour in terms of:
6
+1. Hoisting
7
+2. this binding
8
+3. Syntax clarity
9
+4. Use cases
10
+*/
11
12
+// 1. Function Declaration
13
+greet();
14
+function greet() {
15
+ console.log("Hello");
16
+}
17
18
+// 2. Function Expression
19
+const user = function(user) {
20
+ console.log(`Welcome ${user}`);
21
22
+user("Rafay");
23
24
+// 3. Arrow Function (ES6)
25
+const add = (a, b) => a + b;
26
+add(3, 3);
27
28
29
+// 4. IIFE
30
+(function() {
31
+ console.log("I run immediately!");
32
+})();
0 commit comments