dwyl / technical-glossary

📝 A collaborative technical glossary for key words and terms to help anyone learn and understand concepts and prepare for a career as a creative technologist! 😕 > 🤔 > 💡 > 😊 🎉 🚀
GNU General Public License v2.0
26 stars 5 forks source link

New word: hoisting #8

Closed Brymon closed 2 years ago

Cleop commented 5 years ago

Thanks for adding this one @Brymon 👍

Cleop commented 5 years ago

https://www.w3schools.com/js/js_hoisting.asp

Hoisting is JavaScript's default behaviour of moving var declarations to the top of the current scope when your code is run. What this means is that whatever line your write a var declaration on e.g. var x;, when your code is run it will automatically be lifted and read as if it were written on the top lines of your current scope (to the top of the current script or the current function).

This means that you can use var's higher up in the code before the line you've declared them on. So this example:

x = "hello";
console.log(x)     // logs 'hello'
var x;            //  declaring `x` which is hoisted as if it were written at the top on compilation

Is read by the computer like this:

var x;            //  declaring `x` which has been hoisted to the top line on compilation
x = "hello";
console.log(x)     // logs 'hello'

Can all declarations be hoisted?

Can initialisations be hoisted?

Other words to define:

Cleop commented 5 years ago

@Brymon - if you are happy with the definition that has been added please close this issue 😊

nelsonic commented 2 years ago

https://github.com/dwyl/technical-glossary/tree/677e6a1fd4044ea9752aae75cfc483636f8b5b84#hoisting