DEV Community

Cover image for JS  Hoisting
Dimitris Chitas
Dimitris Chitas

Posted on • Updated on

JS Hoisting

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/

Top comments (0)