Hoisting

I’m confused about hoisting. At the learn path of functions in codecademy it said that hoisting isn’t considered a good practice, I’ve had some doubts about it so I investigated a little further and everyone said that calling a function before it is declared its actually a good practice because it gives readability to the code, so Im a little bit confused about it.

I found this, maybe it helps?

2 Likes

Hello @esisjesus, welcome to the forums!

As well as what @irlfede said, if you call a function before you declare it, and you have a large program, then any other developers that have to look at your code will have to look through lots of code (possibly), before they find the function that is being called:

let someVar = someFun();
//20 lines of code
function someFun() {
return "Imagine looking through 20 lines of code for this.";
}

Hoisting isn’t present in many other languages, which means that is devs mostly work in one language (Python, for instance), then they may get confused.

I hope this helps!

1 Like