December 22, 2022
Estimated Post Reading Time ~

JavaScript What is hoisting

JavaScript What is hoisting?



Hosting
Hoisting is a process in JavaScript where variables and function declarations are moved to the top of their scope before code execution. 

More technically, it is nothing but variables and functions getting attached to the global object before they are accessed.

What are all hoisted? 
Variables and function declarations are hoisted 
⌘ Below ones are hoisted ⌘ 
function(){ } 
var a;

What are all not hoisted? 
Variables and function assignments are not hoisted. 
⌘ Below ones are not hoisted ⌘ 
const greet = function() {} 
var a = 1;

How to avoid hoisting?
To avoid hoisting and unexpected results caused due to hoisting 'use strict' mode 



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.