menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Understand...
source image

Dev

1M

read

325

img
dot

Image Credit: Dev

Understanding Hoisting in JavaScript: Why Can We Use `var` Before Declaration?

  • Hoisting is JavaScript’s default behavior of moving variable and function declarations to the top of their scope before execution.
  • Variables declared with var are hoisted but initialized with undefined, meaning you can reference them before declaration, but they won't hold their actual value until the assignment line is executed.
  • let and const variables are hoisted but not initialized, so accessing them before declaration results in a ReferenceError.
  • Function declarations are fully hoisted, meaning they can be called before being defined.

Read Full Article

like

19 Likes

For uninterrupted reading, download the app