DEV Community

loading...
Cover image for JS  Hoisting

JS Hoisting

feco2019 profile image Dimitris Chitas Updated on ・1 min read

Hello there guys,

I hope you everybody has a nice weekend,creative and passionate for some coding time.

What the hack is hoisting?
It is a term that i used to found commonly when i started learning JS and it is confuse sometimes, but trust me its a just a luxurines of JS that can be explained real quick.

In simple worlds hoisting, points to variable's declaration and initiation.
You can use a variable before you will declare it.
Let's say that you have this :

\\assign value to variable before declaration

name = 'Dimitris';

const showName = () => {
 console.log(name);
}

\\Declare variable after the value's assignment
let name ;

showName();
Enter fullscreen mode Exit fullscreen mode

To understand the above example,you should have the thought in your mind that hoisting means every declaration is going to the top of the programm even if it is physically sits somewhere else.

So above we have a value that is assigned before the variable declaration.Is working fine, Yes you did it you used hoisting.
Congratulations.!

Have a nice workday guys, in case for further explanation do not hesitate to contact me or find me in github or linkedin.
GitHub : https://github.com/feco2019
Linkedin : https://www.linkedin.com/in/dimitris-chitas-930285191/

Discussion (0)

pic
Editor guide