18: Hoisting in JavaScript Explained | What is Hoisting in JavaScript | JavaScript Tutorial




In this JavaScript tutorial you will learn about hoisting in JavaScript. Hoisting is a word you are very likely to run into at some point when coding JavaScript. Hoisting is a term we use to describe when some of the code is allocated space in the browser before the content is shown on a web page.

Meet Daniel: another Full-Stack developer who can teach you coding fast and free πŸ˜€
https://www.youtube.com/channel/UCPIe87uLDW-QZ5FnUZqdxoA

➀ GET ACCESS TO MY LESSON MATERIAL HERE!

First of all, thank you for all the support you have given me!

I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!

I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.

I hope you will find it helpful πŸ™‚

Material for this lesson: https://www.patreon.com/posts/javascript-18-19237826

Original source


27 responses to “18: Hoisting in JavaScript Explained | What is Hoisting in JavaScript | JavaScript Tutorial”

  1. In case of anonymous function, you declared a variable and set it's value equal to an anonymous function. Why hoisting doesn't take place in this case? We have a declartion of a 'variable' having value equal to a function. This variable could have also been hoisted. If not, then why?

  2. when assigning a var to an anonymous function, does that var now become a global var? Global var is loaded to the browser….is this correct? I thought the point of using local var and anonymous functions was to avoid loading info into the browser….? Just a little confused on that.

  3. So global variables are loaded in the browser but local is not and the only time you want to use a global is when you need to access the same var at any point in a .js script script like user input? Correct?

  4. Perennially appreciate, nice explanation:
    Function types:
    – Name function
    – Anonymous function

    – Name function is available defining any part of the source code ( included console log ) as well. Working properly.

    – Anonymous function
    variable name includes function and working well before ( console log etc.)

    * BUT if change position, it cannot work as well. DEFINING FUNCTION is important …

  5. so hoisting hoists up the variable and the name but not the value of the variable? so why does that change when its in a function? if you explained it in the video i apologize but im really trying to understand the dynamics of javascript right now i feel its the only way to grasp it at all….thanks for your knowledge…..edit….is it only because its been given a name?

  6. Hi there, thanks for the video. I'm new to coding, just started recently, so allow me any confusion on my side. Could you maybehelp me with the following points: 1) You explained that hoisting puts your code up at the beginning, but MDN (https://developer.mozilla.org/en-US/docs/Glossary/Hoisting) actually refers to hoisting "a strict definition of hoisting suggests that variable and function declarations are physically moved to the top of your code, but this is not in fact what happens. Instead, the variable and function declarations are put into memory during the compile phase, but stay exactly where you typed them in your code." 2) at 9.48 minutes, while the function itself does not get hoisted, it does seem to me one can't escape hoisting to some extent(?): the anonymous function is actually a variable declaration, so if you would console.log(a) instead of console.log(a()) it would still return undefined because the declaration is getting hoisted. It just doesn't in your example because you are asking for its value – which happens to be function – and like you explained values don't get hoisted. Any feedback is appreciated. Thanks!

Leave a Reply