1//Function declarations load
2//before any code is executed
3//while
4//Function expressions load
5//only when the interpreter reaches that line of code.
6//eg.
7add(1,2);
8function add(a,b){ //this is a function declaration
9 return a+b;
10}
11sum(1,5); //this is a function expression will throw initialization error
12const sum = () => a+b; //function expression is strored in variable
1//Four ways to declare a function
2function add(a, b) {
3 return a + b;
4}
5
6var add = function(a, b) {
7 return a + b;
8}
9
10var add = (a, b) => {
11 return a + b;
12}
13
14var add = (a, b) => a + b;
1//1st (simple function)
2function hello1() {
3 return "Hello simple function";
4}
5
6//2nd (functino expression)
7hello2 = function() {
8 return "Hello functino expression";
9}
10
11// 3rd ( IMMEDIATELY INVOKED FUNCTION EXPRESSIONS (llFE))
12hello3 = (function() {
13 return "Hello IMMEDIATELY INVOKED FUNCTION EXPRESSIONS (llFE)";
14}())
15
16//4th (arrow function)
17hello4 = (name) => { return ("Hello " + name); }
18 //OR
19hello5 = (name) => { return (`Hello new ${name}`) }
20
21document.getElementById("arrow").innerHTML = hello4("arrow function");
22
23document.write("<br>" + hello5("arrow function"));