0% found this document useful (0 votes)
6 views7 pages

Hoisting

Uploaded by

pampapathik12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Hoisting

Uploaded by

pampapathik12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Hoisting

in JavaScript

instagram.com/codewithrafaqat/
youtube.com/codewithrafaqat/
Hoisting
Hoisting in JavaScript refers to the behavior
where variables and function declarations
are moved to the top of the containing
scope during the compilation phase, before
the code is executed.

This allows you to use functions and


variables before they are actually declared
in the code. However, only the declaration
are hoisted, not the initializations.

01 Muhammad Rafaqat
React Developer
Variable Hoisting
Variable hoisting in JavaScript involves the
behavior where variable declarations (using
var) are moved to the top of their enclosing
function or global scope during the
compilation phase.

Using var:

02 Muhammad Rafaqat
React Developer
Using let and const:

Variables declared with let and const are


also hoisted ,but they are not initialized.

Accessing them before their declaration


results in a ReferenceError due to temporal
dead zone (TDZ).

03 Muhammad Rafaqat
React Developer
Function Hoisting
Function Declarations:

When you declare a function using a


function declaration, the entire function
(both its name and body) is hoisted to the
top of its scope.

This means you can call the function before


the point where it is actually defined in the
code.

04 Muhammad Rafaqat
React Developer
Function Expressions:

Function expressions are not hoisted in the


same way.

If you assign a function to a variable


(whether using var, let or const), only the
variable declaration is hoisted, not the
function assignment.

05 Muhammad Rafaqat
React Developer
Did you find It
Useful?

Muhammad Rafaqat
@codewithrafaqat

Follow For More!

Like Comment Repost

instagram.com/codewithrafaqat/
youtube.com/codewithrafaqat/

You might also like