DEV Community

CalebMcCoy04
CalebMcCoy04

Posted on

2 1

Hoisting

Hello, Just wanted to chat about a topic that confused me in the beginning, hoisting.
Hoisting refers to setting variables, functions, or classes to the top level of their scope.

const hoistedVariable = 1
//this is hoisted 
function something(){
return hoistedVAriable + 1
}
Enter fullscreen mode Exit fullscreen mode

const and let both can be hoisted but are not initialized.

Where as if we had some variable declared within a function it would not be hoisted.

function Something(){
const notHoisted = 2
// not hoisted
return notHoisted + 4
}
Enter fullscreen mode Exit fullscreen mode

the above examples show hoisted vs not hoisted.
there is some interesting stuff with var but for me best practice its not to use var so that wont be covered here.

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay