All VideosJavaScript Tutorials

What is Hoisting in JavaScript | JavaScript Tutorials in Hindi | Interview Question #20

In JavaScript, hoisting is a mechanism that moves variable and function declarations to the top of their respective scopes before the code is executed. This means that regardless of where declarations are made in the code, they are treated as if they were declared at the beginning of their scope.

Hoisting applies to both variables and functions, but it works differently for each of them. Variable declarations are hoisted, but their initializations are not. This means that if you declare a variable at the bottom of a scope and try to use it before it is initialized, you will get an undefined value. On the other hand, function declarations are hoisted entirely, so you can call a function before it is declared.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!