DEV Community

narender2031
narender2031

Posted on

Hoisting in JavaScript

When a JavaScript function executes it creates a global execution context. There are two-phase in the global execution context.

  • Creation
  • Code execution

In the Creation phase, javaScript allocates the memory to the variables and functions. For the variables, it allocates the placeholder value called undefined. In the case of the function, it saves the function to the memory.

So When you called the function before the define the function it works. But in the case of the Variables, it returns the undefined.

Top comments (0)