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;


Hassan Habib Tahir

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store