JavaScript Hoisting

Yohan Malshika
2 min readSep 15, 2018

--

I think all of you know about JavaScript Function Expression and Function declaration .

In this example for Function Expression and Function Declaration. Key difference between these two functions, is we can call this function the one that is defined using the function declaration syntax before it is defined.

so this function declaration method (walking()) , give the output like this. but function expression method (walk()), give the error. because JavaScript engine executes this code, it moves all the function declarations to the top. so this code will look like this at run time.

This is what we call hosting.

so Hoisting is the process of moving function declaration to the top of the file and this done automatically by the JavaScript engine that is executing this code.

so this is a reason we can call functions that are defined using the function declaration syntax before the definition.

--

--