Function Hoisting

Hosting is JavaScript default behavior where variables and functions declaration move to top of their scope before code execution. and we can call before declared!

1 console.log(sum(3, 5))

2 function sum(a, b) {

return a + b

}

when you call line one it auto declare on the top function move to the top because function is itself declaration and call it , it give the results but the variable hosting is no do as like this . because variable declaration is going top not is the initialization

let a

console.log(“A IS “, a)

// a is declare with undefined and it gives the value when the initilization line is execution

a = 56;

this same concept of variable it used same in function expression

console.log(getRectArea(3, 4));

let getRectArea = function (width, height) {

return width * height;

};

--

--