Learn JavaScript Hoisting In 5 Minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024

ความคิดเห็น • 226

  • @WebDevSimplified
    @WebDevSimplified  2 ปีที่แล้ว +162

    IMPORTANT: I want to make a few clarifications to this video based on some comments.
    1. JavaScript does not actually move your code around before executing. I know I talk a lot about how JavaScript will act like it moves your functions to the top of your file, but it doesn't actually do this moving. In reality what happens is it first reads your code before executing the code so it knows which functions you have defined before executing. This is really not important, though, as all that matters is how the code actually works and not what happens with your code when the computer parses it.
    2. One thing I did not mention in this video is how hoisting works within scopes. For example if you define a function called a and inside that a function you define another function called b the b function would only be hoisted to the top of the a function since the b function is inside the scope of the a function. I probably should have covered this, but this topic is more related to scoping which could be its entirely own video.
    3. Technically, let and const are actually hoisted, but they are not initialized with a value which is why you get an error when trying to use them before they are declared. The code example people use to demonstrate this generally looks like this.
    function log(){
    console.log(value)
    }
    let value = 1
    log() //output: 1
    In this example value is technically used above where it is declared, but it is used inside a function that is called after value is defined which is why there is no error. In some programming languages this would cause an error, but not in JavaScript. For these types of examples you can still use the top to bottom nature of JavaScript to understand what is happening and see why this works. First we define a function called log. None of the code in this function is executed when we define it so we can ignore the code in the function for now. Next we define a variable called value and set it to 1. Finally we call the log function we defined previously which prints out the variable value. As you can see from this top to bottom example the variable value is only ever used after it is defined which is why there is no error and for all intents and purposes you can treat let/const as if they are not hoisted since they are not able to be used before initialization like var/function.
    Now the reason I did not include all this information is for 2 reasons (I did not know some of it, and it is irrelevant). The point of this video is to help someone that does not understand hoisting understand what it is, how you can use it, and why it is important. I could have made this video 10-20 minutes long and talked about every edge case and technicality behind hoisting, but that needlessly bloats the video, makes things much more complicated for someone just learning hoisting, and goes against everything my channel is about. I called the channel Web Dev Simplified for a reason. I want to simplify the web for everyone and not worry about technicalities that don't impact how your program day to day.
    In my opinion this video covers all the main concepts behind hoisting without being too long or too complicated so that someone can easily watch this video and walk away with a solid understanding of what they need to know about hoisting to do work as a developer. For example, I had no idea that let and const were technically hoisted when making this video, but I have never ran into an issue where that information would have been relevant in my development career so it probably isn't important for me to teach in this video even if I did know it.

    • @fluffyniki3257
      @fluffyniki3257 2 ปีที่แล้ว +22

      I bet it took you to write this comment longer than making this video 😆

    • @yuvalazaria
      @yuvalazaria 2 ปีที่แล้ว +2

      Thanks for the extra info Kyle!

    • @WebDevSimplified
      @WebDevSimplified  2 ปีที่แล้ว +47

      @@fluffyniki3257 If you believe this, then you severely underestimate how long it takes to make a video. Even a simple 5 minute video like this takes much longer than writing out a few paragraphs of text.

    • @evangeloskolimitras5276
      @evangeloskolimitras5276 2 ปีที่แล้ว +10

      I suggest you re-upload the video. There are many missing points you did not cover as you already mentioned in your comment. The quick answer on the whats and hows of hoisting is "the two step compilation process". By that token you will also cover hoisted scopes. Just a suggestion. Don't get me wrong but your video now creates more confusion than it solves, especially for beginner javascript devs.

    • @kenkletzien1210
      @kenkletzien1210 2 ปีที่แล้ว

      Great stuff, as always, Kyle. Just fyi, the expression is "for all intents and purposes."

  • @colinb8332
    @colinb8332 2 ปีที่แล้ว +113

    I would really recommend people going to the MDN documentation. There’s some weirdness of hoisting that they give good examples of. Especially in concern of block scopes.

    • @mudassirakhter6605
      @mudassirakhter6605 2 ปีที่แล้ว +1

      Exactly 💯

    • @dopetag
      @dopetag ปีที่แล้ว +2

      Great and short read which makes a lot of sense!
      So it's basically:
      1. for functions:
      Being able to use a variable's value in its scope before the line it is declared. ("Value hoisting")
      2. for var:
      Being able to reference a variable in its scope before the line it is declared, without throwing a ReferenceError, but the value is always undefined. ("Declaration hoisting")
      3. for let, const and class:
      The declaration of the variable causes behavior changes in its scope before the line in which it is declared.

  • @7heMech
    @7heMech 2 ปีที่แล้ว +5

    Oh, isn't that common sense though?

    • @BrightCode
      @BrightCode 2 ปีที่แล้ว +2

      Not really

  • @jnsjknn
    @jnsjknn 2 ปีที่แล้ว +5

    Hoisting is a made up term that doesn't exist anywhere in the ECMAScript specification. It is a useful shortcut to explain why you can reference functions before their initialization but that's all it really is. The actual reason for this behavior is due to the two phases of the JavaScript interpreter. Here's a lot better explanation of "hoisting" by Brad on Traversy media: th-cam.com/video/Fd9VaW0M7K4/w-d-xo.html

    • @Laura69
      @Laura69 2 ปีที่แล้ว +1

      Really useful, thanks for sharing it.

    • @robertholtz
      @robertholtz 2 ปีที่แล้ว +3

      You're quite right. If more developers understood the phases of the Global Execution Context, we wouldn't need terms like "hoisting." To your point, telling developers that hoisting is the equivalent of moving declarations to the top of the file, while easy to grasp, is also an incredibly inaccurate explanation of what's actually happening. In many ways, it fuels the confusion on this subject. Here I have the quirky advantage of being old. For a long long time, ALL interpreters needed a separate memory creation phase that preceded code execution. You had to know up front if you had enough memory to to store and act upon your objects and methods, otherwise there was no point in proceeding to runtime and very likely overflowing the execution stack. It's something young developers pretty much never need to think about or concern themselves with because memory space is generally so abundant, stable, and dirt cheap. That said, it consistently explains everything a modern developer would ever need to know about what we collectively call hoisting. By the way, technically, const and let ARE also "hoisted" to memory but just not to the global scope. They are waiting patiently for us in a special allocation we used to call "reserve memory" or a "reserved block" - what the official ECMA spec hilariously calls the "Temporal Dead Zone." But that's a whole other conversation. Cheers! ...and thanks for your great comment.

  • @Sindoku
    @Sindoku 2 ปีที่แล้ว +2

    let and const are hoisted, it’s just they don’t get assigned a default value like var does. It’s an incredibly small detail, but it’s worth nothing if you truly want to understand hoisting.

  • @StrayKev
    @StrayKev 2 ปีที่แล้ว +107

    2:34 - 3:00 let and const are hoisted
    MDN web docs:
    Variables declared with let and const are also hoisted but, unlike var, are not initialized with a default value. An exception will be thrown if a variable declared with let or const is read before it is initialized.
    Example:
    function foo(){
    console.log(bar)
    }
    let bar = 1
    foo(); //output: 1

    • @Issvor
      @Issvor 2 ปีที่แล้ว +8

      Akshay Saini does a pretty good job at explaining hoisting in his Namaste Javascript series on youtube, and goes into detail about how the call stack works and why let and const are hoisted, but in a different manner than var

    • @ashy7198
      @ashy7198 2 ปีที่แล้ว +11

      if they are hoisted but not initialized, isnt that just the same as them not being hoisted in the first place? Or am i missing something?

    • @StrayKev
      @StrayKev 2 ปีที่แล้ว +6

      ​@@ashy7198
      Written code:
      function foo(){
      console.log(bar)
      }
      let bar = 1
      foo() //output: 1
      Equivalent code or when hoisting is applied:
      let bar
      function foo(){
      console.log(bar)
      }
      bar = 1
      foo() //output: 1
      Another way of thinking about hoisting is that memory will be allocated for variables and functions before execution. If variables aren't hoisted then the code above would throw an error inside the function stating that bar is undeclared.
      Does this make sense?
      As mentioned by another comment, I recommend this video for a deeper dive on hoisting/execution context: th-cam.com/video/Fd9VaW0M7K4/w-d-xo.html

    • @ashy7198
      @ashy7198 2 ปีที่แล้ว +1

      @@StrayKev yes! That does make sense thanks for clearing that up for me 🙂

    • @memoryleakerz
      @memoryleakerz 2 ปีที่แล้ว +1

      @@StrayKev If I am not mistaken here the reason for this is that while JavaScript is interperted is that it is ran twice, once for memory allocation and once for execution :)

  • @buondevid
    @buondevid 2 ปีที่แล้ว +10

    let and const are actually hoisted, you get a reference error if you try to access them in their TDZ (i.e. Temporal Dead Zone) which is different from them not being hoisted at all

  • @roshanacharya4618
    @roshanacharya4618 2 ปีที่แล้ว +3

    Make sure you know what you are talking about before making a video. You are that dude in 00:03

    • @WebDevSimplified
      @WebDevSimplified  2 ปีที่แล้ว

      I would love if you could explain what you feel I did wrong or messed up in this video so I can correct it. I also added a pinned comment to this video with some clarifications based on comments.

  • @muhebollahkhandaker
    @muhebollahkhandaker 2 ปีที่แล้ว +10

    When running the JS code, a global execution context is created. It is created in two phases:
    1. Creation Phase
    Creation of the Variable Object
    Creation of the Scope Chain
    Setting the value of this keyword
    2. Execution Phase
    Runs code line by line.

    • @its_maalik
      @its_maalik 2 ปีที่แล้ว +4

      This is the correct answer. I was about to post this as well.

    • @robertholtz
      @robertholtz 2 ปีที่แล้ว +1

      Thank you for rectifying that.

    • @muhebollahkhandaker
      @muhebollahkhandaker 2 ปีที่แล้ว

      @@robertholtz welcome

    • @muhebollahkhandaker
      @muhebollahkhandaker 2 ปีที่แล้ว

      @@its_maalik thanks

  • @eitanwaxman1862
    @eitanwaxman1862 2 ปีที่แล้ว +3

    Doesn't this make using the function keyword somewhat superior to declaring functions with const? Except for being hip and ES6, what are the advantages to using const?

    • @symix.
      @symix. 2 ปีที่แล้ว +1

      Not changing 'this' when needed, for example if 'this' is something else than window

  • @theisoj
    @theisoj 2 ปีที่แล้ว +7

    Thanks Kyle! Best tutorial ever!

    • @adarsh-chakraborty
      @adarsh-chakraborty 2 ปีที่แล้ว +4

      Bruh atleast watch the full video.
      He said 5 mins not 18 seconds

    • @cresent6568
      @cresent6568 2 ปีที่แล้ว +3

      Video came out 2 minutes ago. How have you even watched it so quickly smh

    • @anipezalt4422
      @anipezalt4422 2 ปีที่แล้ว +1

      Yeah right

    • @theisoj
      @theisoj 2 ปีที่แล้ว +1

      @@adarsh-chakraborty I'm watching the full video, but I'm always here in the comments section commenting, as always.

  • @WebDevChallenge-Ethiopia
    @WebDevChallenge-Ethiopia 2 หลายเดือนก่อน +1

    Web Dev Challenge-Ethiopia

  • @grumpylibrarian
    @grumpylibrarian 2 ปีที่แล้ว +2

    I would strongly recommend avoiding this. Hoisting is going to make your code harder to read. It's right up there with "import *" and global variables in making it really hard to see where a particular function or variable comes from. When ES6 introduced class declarations, they did remember to not allow hoisting even when done as a declaration ("class MyCLass{") instead of an expression ("const MyClass=class{"). They then went and immediately blew it by allowing blind imports with "import *" that obscure from which module an asset was imported.
    There's another problem with using the "function" keyword in general, either as declaration or expression: they can be treated as either methods or constructors. Especially for functions exported out into the big scary real world, you should allow a function to be a constructor OR a method, and never both. Class constructors will throw an error if they're called without the "new" keyword. Arrow functions will throw an error if called with the "new" keyword. What some gentle viewers might or might not know is that class methods and object methods also with throw errors if used with "new":
    class MyClass{
    constructor(){
    //This will throw if not called with "new"
    }
    aMethod(){
    //This will throw if called with "new" even if separated from the class
    //such as with "const aMethod=MyClass.prototype.aMethod;new aMethod()"
    }
    }
    const someObject{
    bMethod(){
    //This will also throw if called with "new" even if separated from the object
    },
    cMethod: function(){
    //This will NOT throw if called with "new" because it's a pointer to a function
    //and not a class/object method
    },
    }
    function dFunction(){
    //This will not throw if called with or without "new"
    }
    const eArrow=()=>{
    // this will throw if called with "new"
    }
    Arrow functions are a good idea for general-purpose methods. They have the characteristics of A) lexical (code-position) inheritance of "this" and B) inheritance of the "arguments" variable from the lexical scope as well. These are often either desired or not a problem, which is good, because JavaScript doesn't have a clean way to make just a method otherwise. I've used a few patterns, and this is ugly but as good as any:
    const {method}={method(){
    // this will throw if called with "new"
    }}
    Finally, this can't be done with generators or async generators, and they're all technically constructors as they create the iterator object. Fortunately, "new" doesn't work with them, and you'll likely get a "not a constructor" error even though it is internally. The "this" value will even kindly work properly, even though the iterator object is not the same as the object holding the generator.

  • @marna_li
    @marna_li 2 ปีที่แล้ว +3

    It all comes down to the history of JavaScript and how Var and Function is implemented. These constructs are members of the enclosing Function object or Global object - to which the variable is scoped. Vars are not scoped to blocks.
    Since JavaScript runs from top down the Var statement is not executed until the line is hit and the member not created until then. Function declarations are treated differently, detected when the code is parsed, and the identifier/name is hoisted. Let and Const are later inventions that are implemented a bit differently and don't result in members on the enclosing object. That is why they are not hoisted.

  • @bertlemoi431
    @bertlemoi431 2 ปีที่แล้ว

    does hoisting breech the encapsulation barrier of frameworks like react/angular/etc?
    and please watch kevin's video about moving lines up and down (ALT + UP/Down to move the line up/down one line). it's driving me nuts haha

  • @citlaliserratos6066
    @citlaliserratos6066 7 วันที่ผ่านมา

    Comment made after watching a useful video so I don't forget what it was about #1.
    So, hoisting is like a hierarchy that JavaScript follows when some code is running, I mean, functions and var come on top of everything even when those are declared later butt const, let and more are the mortal ones and have to wait for their turn and, if they're called before they are declared, there's an error.

  • @Tubeytime
    @Tubeytime 6 หลายเดือนก่อน

    JS dev: I made this language that lets you write your own code!
    JS dev: also it changes your code without your consent! 😈

  • @grijjly6091
    @grijjly6091 2 ปีที่แล้ว

    Last example is wrong. When you log a before define, javascript checks window.a which is undefined

  • @meqativ
    @meqativ 2 ปีที่แล้ว +1

    i kinda understanded hoisting before this video, but now i understand it completely (me dumb basically)

  • @JohnLittler
    @JohnLittler 2 ปีที่แล้ว

    "var is probably something you should never use in programming" ... unless you prefer to use it and have used it way before let came along and it makes no difference to the way you code anyway, so go jump!

  • @jamesreynolds3167
    @jamesreynolds3167 2 ปีที่แล้ว

    My work uses an old version of a js framework that can't be transpilled. And we require IE support.
    So we have to use var instead of let and const in our legacy front end.

  • @davidfenwick5194
    @davidfenwick5194 ปีที่แล้ว

    You talk waaay to fast bro. JS is hard enough to understand without you talking 100 MPH!

  • @ДмитрийКарпич
    @ДмитрийКарпич 2 ปีที่แล้ว

    And moral of this story - always use linter at strict mode, and don't anything creepy in you code, moreover at you teem code. Write so simple, that every junior developer can understand you code without disturbing you.

  • @vivekkumar36732
    @vivekkumar36732 2 ปีที่แล้ว +6

    Very basic, but it's always good to refresh your basics

  • @Rafps3player
    @Rafps3player 2 ปีที่แล้ว +4

    As always super clean and concise in explaining the concepts; you are great!

  • @DevMeloy
    @DevMeloy 2 ปีที่แล้ว

    I don't think you're correct that const not being hoisted.. if that was true the error would be a reference error, not an initialize error.. const must be initialized;

  • @bryanDevsJS
    @bryanDevsJS ปีที่แล้ว

    great video can you give me roadmap for javascript I want to be a backend devs with this javascript spell

  • @tarearnaut3502
    @tarearnaut3502 2 ปีที่แล้ว

    why tf does JS has all of these weird names that you cant even guess anything about it from the name, so annoying. Like the most simple thing, problem, has a weird ass name.

  • @kaziupir
    @kaziupir 2 ปีที่แล้ว +1

    Actually it doesnt move any code, but reads code before running and save in memory.

  • @mrxgamer7567
    @mrxgamer7567 ปีที่แล้ว +1

    very clean explaination !

  • @bryanthompson1070
    @bryanthompson1070 2 ปีที่แล้ว +8

    Good simplified explanation. Brad at Traversy Media deep dives the JavaScript engine in his JavaScript Under The Hood series if you want a more thorough understanding of hoisting

    • @noy1009
      @noy1009 2 ปีที่แล้ว

      have u got a link mate?

    • @bryanthompson1070
      @bryanthompson1070 2 ปีที่แล้ว

      @@noy1009 th-cam.com/video/Fd9VaW0M7K4/w-d-xo.html

  • @kevinbatdorf
    @kevinbatdorf ปีที่แล้ว +1

    The real lesson here is to use const to define functions so that you don't get unexpected or confusing behavior, as you highlight at 1:18

  • @naumansulaiman8856
    @naumansulaiman8856 2 ปีที่แล้ว

    Kyle, ignore the idiots posting the criticism. If they know this stuff they dont even need to be watching this vid

  • @7heMech
    @7heMech 2 ปีที่แล้ว +2

    Thanks.

  • @mohammadvempalli3973
    @mohammadvempalli3973 2 ปีที่แล้ว

    Am i only one who thinks Kyle is pretty much suitable for Peter Parker 😅

  • @robertholtz
    @robertholtz 2 ปีที่แล้ว +10

    I know there is a lot of recent hate for var because const and let are more precise in their scoping. That said, in my opinion, there are still valid use cases for choosing var over let. If you want to make sure a variable or variable-function is always scoped globally, var is still a good way to go. That, of course, gives rise to the argument against the use of globals in general but that's a separate debate. Global scoping actually removes code complexity if you use it properly and sparingly.

  • @alwysrite
    @alwysrite 2 ปีที่แล้ว

    and now that you spoke about hoisting, can you talk a bit about hosting - ie websites to host for beginners please.

  • @Sartaj.MarvelMinds
    @Sartaj.MarvelMinds หลายเดือนก่อน

    Functions are not moved to the top but it's declaration is hoisted to the top, the function code remains where it is.

  • @moheaali2049
    @moheaali2049 11 หลายเดือนก่อน

    let and const variables are hoisted, only they are hoisted without a default initialization.

  • @flowerofash4439
    @flowerofash4439 2 ปีที่แล้ว

    just when you think javascript cannot get any worse, but it does

  • @Arabian_Abomination
    @Arabian_Abomination 2 ปีที่แล้ว +1

    Please do more on closures and other weird parts of js

  • @aryansharma8794
    @aryansharma8794 2 ปีที่แล้ว

    It is good but also Watch Akshay saini series on javascript

  • @syedsaadali6765
    @syedsaadali6765 2 ปีที่แล้ว

    I understood hoisting just from the thumbnail alone :o

  • @kenbinta2246
    @kenbinta2246 2 ปีที่แล้ว +1

    A daily dose of Web Dev Simplified makes one a better programmer

  • @abcq1
    @abcq1 2 ปีที่แล้ว

    "...to make themselves seem smarter, like they know what they're talking about..."
    And then you talk about things you know nothing about. Sry, but it's better for you as a mediocre junior dev to learn things for yourself before trying to teach them.

    • @WebDevSimplified
      @WebDevSimplified  2 ปีที่แล้ว

      I would love if you could explain what you feel I did wrong or messed up in this video so I can correct it. I also added a pinned comment to this video with some clarifications based on comments.

  • @amgdeg4897
    @amgdeg4897 2 ปีที่แล้ว

    This video feels emotionally motivated
    Which isn't a bad thing if it is

  • @sak1b
    @sak1b 2 ปีที่แล้ว

    If anyone wants to deep dive just look for "namaste js"

  • @ukaszzbrozek6470
    @ukaszzbrozek6470 2 ปีที่แล้ว +2

    The way how hoisting works is that there is a creation phase when the code is executed where all declare values in certain scope are initilize. There is no moving code around.

    • @Tubeytime
      @Tubeytime 6 หลายเดือนก่อน

      Regardless, this creation phase is hidden from the programmer. It is essentially a program that runs outside your program which you can't switch off.

  • @jaerb1
    @jaerb1 2 ปีที่แล้ว

    Ukraine. коментар заради коментара

  • @olga_lc
    @olga_lc 2 ปีที่แล้ว

    Thanks, I didn't know it was called 'hoisting'

  • @8siaix
    @8siaix ปีที่แล้ว

    you got a Jackson, you are aa Metaliprogrammer

  • @namucho266
    @namucho266 2 ปีที่แล้ว

    The first video of yours that I did not like...

  • @jossani6712
    @jossani6712 2 ปีที่แล้ว +1

    Really good explanation about the topic, also i really love your content, you are helping me become a greater developer, thanks Kyle

  • @alexgolomb363
    @alexgolomb363 6 หลายเดือนก่อน

    Do you play the guitar intro in your videos?

  • @ajzack983
    @ajzack983 2 ปีที่แล้ว

    Thank u ,
    Teach a man how hoist and he will have func for life

  • @topherlions714
    @topherlions714 2 ปีที่แล้ว

    This is a common interview question!!

  • @das6109
    @das6109 ปีที่แล้ว

    Is a function defined in another function hoisted?

  • @marimuthur9456
    @marimuthur9456 2 ปีที่แล้ว

    It's very easy to understand thank you so much for your explanation about hosting 😊👌🏼👌🏼👌🏼👌🏼👌🏼

  • @lucienchu9649
    @lucienchu9649 2 ปีที่แล้ว

    hoisting is definitely an interview question for EVERY js programmer, followed by "this", hhhhhh

  • @nitigyajoshi4658
    @nitigyajoshi4658 2 ปีที่แล้ว

    brooooooooooo..........you can explain so nicely!

  • @EngineBoy
    @EngineBoy 2 ปีที่แล้ว

    Let & const are also hoisted but you got reference error by calling inside temporal dead zone. & JavaScript doesn't move any function at top of file it gets parsed into the memory while memory allocation process.

  • @SAKSHIKUMARIP
    @SAKSHIKUMARIP ปีที่แล้ว

    u break down evry complex concepts..keep uploading more such js vid.!!!!!! huge respect...

  • @funstories728
    @funstories728 ปีที่แล้ว

    You are really dope at explaining

  • @alejowtf917
    @alejowtf917 2 ปีที่แล้ว

    Isn’t this just basic concepts that you learn on languages like C?

    • @rastaarmando7058
      @rastaarmando7058 2 ปีที่แล้ว +1

      You don't know what you are talking about.

  • @eldyko
    @eldyko 2 ปีที่แล้ว

    Good to know but let’s declare shit before we call it. Ps. Sick axe. Play me some Def Leppard!

  • @danielbarua6809
    @danielbarua6809 2 หลายเดือนก่อน

    helpful. i wish i click earlier .

  • @archrodney
    @archrodney 2 ปีที่แล้ว

    I read in the O'Reilly book that even import statements are hoisted:
    10.3.2 ES6 Imports
    "By near-universal convention, the imports needed by a module are placed at the start of the module. Interestingly, however, this is not required: like function declarations, imports are hoisted to the top, and all imported values are available for any of the module's code runs."

  • @devl0ver666
    @devl0ver666 7 วันที่ผ่านมา

    i really like your videos bro

  • @elakkiyas7142
    @elakkiyas7142 ปีที่แล้ว +1

    we love not only your course😁

  • @muhammad_abir
    @muhammad_abir 2 ปีที่แล้ว

    make more videos like this.....

  • @zdfvbadfbadb
    @zdfvbadfbadb 2 ปีที่แล้ว

    Nice simplification of this topic, Kyle! As seen in the comments here, hoisting is one of those topics that mostly just let's the nerds come out and try and show how smart they are. Really, though, outside of job interviews, the concept is largely irrelevant. Not because it is not important, but because of how easy it is to spot and fix if you do get it wrong. Oh, got an error... 30 seconds later, oh, just need to move this line above that line...done. Not a big deal (unless you just want to show how smart you are by blasting a brilliant TH-camr).

  • @hyderabadipunch1152
    @hyderabadipunch1152 2 ปีที่แล้ว

    Hey Kyle...awesome lesson. Thanks. Can you tell me how you skipped using semicolons in your file.

  • @AniMason-Animation
    @AniMason-Animation 2 ปีที่แล้ว

    Good at teaching code and styling your hair. Very informative video with great explanations:)

  • @danielnadar75
    @danielnadar75 ปีที่แล้ว

    You are wonderful Kyle❤

  • @codeisnotevil7993
    @codeisnotevil7993 2 ปีที่แล้ว

    IMO Hoisting makes js more unintuitiv and harder to debug, a clear error because would be much nicer.

  • @lubnaarora4946
    @lubnaarora4946 11 หลายเดือนก่อน

    Effective explanation

  • @niruddhaRoy
    @niruddhaRoy 2 ปีที่แล้ว

    Hey kyle, I am big fan the way you describe the issue, many ideas and pr i resolved after watching your tuts, I have an request can you make a tutorial on @mentions, that we find on any chat app, how we can do this?
    Thanks very much for your effort.

  • @yukimoe
    @yukimoe 2 ปีที่แล้ว

    All this time I thought undefined variables just return undefined, but actually they only return undefined if you declare it somewhere otherwise that's an error

  • @lioraharon98
    @lioraharon98 ปีที่แล้ว

    Actually i can say this is very important because i was having interview about hoisting and they gave me the same tricky questions
    It's a very popular question on javascript interview

  • @Key-yf3ou
    @Key-yf3ou ปีที่แล้ว

    You are awesome, thank a lot

  • @alexjohnson-bassworship3150
    @alexjohnson-bassworship3150 2 ปีที่แล้ว +1

    Kyle - I think you did a great job, and I think you're right. The point of a video like this is to give the general overview to someone who does not understand what the concept is and to simplify it. If they would like to know more, there are always docs that they can go look at elsewhere. I also know you like to do your blog posts so I'm sure you will do one at some point on this topic if you haven't already. All in all, disregard the people who have to make it such a big deal to write negative comments when you clearly created such an amazing channel that has helped individuals like me learn way more than I ever thought I could learn without formalized education. Keep it up, my man!

    • @boxboxerson991
      @boxboxerson991 2 ปีที่แล้ว +2

      You shouldn't encourage him to ignore feedback. He's explaining why it works like that, the details matter. And for someone who focuses most of his time on cringe thumbnails and very opinionated topics you'd think he can manage less than constructive feedback.

    • @traceuse13
      @traceuse13 2 ปีที่แล้ว

      I agree. This video is awesome. Everyone needs to freaking chill. Kyle does really amazing work and thanks to him, I was able to learm faster and get a job.

  • @ReejohnStellas
    @ReejohnStellas 2 ปีที่แล้ว

    Thanks bruh
    looking forward to see more videos of yours

  • @petrmai9152
    @petrmai9152 2 หลายเดือนก่อน

    OH! MY! GOD!
    WOW! just WOW!

  • @skjahir7365
    @skjahir7365 ปีที่แล้ว

    Great explanation :)

  • @sawannirala2464
    @sawannirala2464 2 ปีที่แล้ว

    Namaste JavaScript described in more details. @akshay_saini

  • @nickthequick13
    @nickthequick13 2 ปีที่แล้ว +1

    So what's the advantage of using const for functions? Only when you don't want it hoisted and if so when would that be?

    • @majorhumbert676
      @majorhumbert676 2 ปีที่แล้ว +1

      My opinion:
      1. Consistency with the rest of the syntax. Treat functions as any other type (string, number, object, etc.). I like to only use arrow functions in my code.
      2. No function scope. Virtually everyone agrees that we shouldn't use 'var', so let's apply the same standard to functions.
      3. Arrow functions doesn't bind 'this'. 'this' has a lot of weirdness and I find it easiest to just not use it at all. That means no usage of 'function', 'new', or 'class'. These features are just not needed. Use closures instead. Closures is largely what makes JavaScript an amazing language.
      There's generally no reason to hoist stuff. When you export arrow functions from modules, the order of the function declarations doesn't matter anyways. When you declare functions within another function, just use arrow functions and limit yourself to block scopes. So I'd only use arrow functions and never use 'function'.

    • @nickthequick13
      @nickthequick13 2 ปีที่แล้ว +1

      @@majorhumbert676 thanks for awesome reply. It's cool when people are so helpful just to be nice

    • @majorhumbert676
      @majorhumbert676 2 ปีที่แล้ว

      @@nickthequick13 It's my pleasure

  • @u-codegate1239
    @u-codegate1239 2 ปีที่แล้ว

    why i love HTML & CSS & JS

  • @Tesseract9630
    @Tesseract9630 2 ปีที่แล้ว

    As always aswome video.

  • @maniac1441
    @maniac1441 2 ปีที่แล้ว

    Helpful 💕

  • @heyitsgagan
    @heyitsgagan 2 หลายเดือนก่อน

    Thankyou sir

  • @Noritoshi-r8m
    @Noritoshi-r8m 2 ปีที่แล้ว

    Ty sir!

  • @shashisharma9367
    @shashisharma9367 2 ปีที่แล้ว

    Named function doesn't get moved to the top of the file rather it's copied within the memory itself and the same for const and let, it's just they are not assigned a value until and unless the program run.
    The steps are like 1. copy named functions and all the const, let and var to the memory
    2. then run the run code from the memory

  • @sebastianbraun2473
    @sebastianbraun2473 2 ปีที่แล้ว

    Coming from Java, this makes absolutely sense :)

  • @jim4nz
    @jim4nz 2 ปีที่แล้ว

    More in depth hoisting is due to LFS = RHS reference, javascript act as compiler where they will define LFS (left hand side) first prior code execution

  • @yahyasalimi3254
    @yahyasalimi3254 2 ปีที่แล้ว +16

    Pro tip: You can use ALT + up/down to move line of code up or down instead of cutting and pasting
    Btw very good video, it really helped to understand the topic

    • @Dontcaredidntask-q9m
      @Dontcaredidntask-q9m 2 ปีที่แล้ว +14

      @Jojo there's nothing wrong with saying you can do this... anyway, protip: get out and talk to some real people

    • @nonnodacciaio704
      @nonnodacciaio704 2 ปีที่แล้ว

      @Jojo i wonder why you thought of saying this

    • @TopBagon
      @TopBagon 2 ปีที่แล้ว +2

      @Jojo I wonder if your name is a jojo reference

    • @fluffyniki3257
      @fluffyniki3257 2 ปีที่แล้ว

      You can press alt and wherever you click will be cursor
      Or was it ctrl 🤔

    • @yahyasalimi3254
      @yahyasalimi3254 2 ปีที่แล้ว

      @@fluffyniki3257 You made me think again. I checked again and it is definitely ALT. Pressing Ctrl does not move line. It only moves screen up/down

  • @ibrahim_youssef_13.12
    @ibrahim_youssef_13.12 ปีที่แล้ว

    perfect as ever you

  • @shortsScroll
    @shortsScroll 6 หลายเดือนก่อน

    Love you bro 🥰🥰🥰🥰

  • @jfirestorm44
    @jfirestorm44 2 ปีที่แล้ว

    Well I learned something new today. Thanks for the great vid.

  • @jenso413
    @jenso413 2 ปีที่แล้ว

    yo, you got any guitar videos? I’d love to see web dev simplified shred it up haha

  • @AbdulFourteia
    @AbdulFourteia 2 ปีที่แล้ว

    I understand you are eager to share learning tips, but you should make sure to share the correct information. You have done this on more than one occasion.