The this Keyword

Поделиться
HTML-код
  • Опубликовано: 17 сен 2024
  • The ‘this’ keyword is extremely important concept to understand in JavaScript. Many beginners find it especially difficult to understand ‘this’ keyword. But don’t worry, it’s actually not that hard if you know exactly how the ‘this’ keyword works.
    The ‘this’ keyword or ‘this’ variable is basically a special variable that is created for every execution context and therefore any function.
    In fact, we learned before, that it is one of the three components of any execution context along with the variable object and scope chain that we already covered.
    In general terms, the ‘this’ keyword will always take the value of the owner of the function in which the ‘this’ keyword is used. We also say that it points to the owner of the function.
    Now, before I explain how the value of this keyword is determined, keep in mind, the value of this keyword is not static. So, its not always the same. It depends on how the function is actually called. The value of ‘this’ variable is only assigned when the function is actually called i.e. at runtime.
    The value of this can be determined depending on how the function is called. In this lecture, lets understand how value of this variable is determined.

Комментарии • 14

  • @koko-mt7zr
    @koko-mt7zr Год назад +5

    I have a question why you don’t have one million sub man your content is so cool and amazing keep up man thank you very much

  • @bishwajeetpandey1570
    @bishwajeetpandey1570 Год назад +3

    Your explanation is really great, i m so lucky to find such a great channel ❤️

  • @macusgeorgiev9821
    @macusgeorgiev9821 3 года назад +1

    Great explanation! I am glad I found your channel. Thanks!

    • @procademy
      @procademy  3 года назад

      Thanks for watching!

  • @russelldriver6394
    @russelldriver6394 3 года назад

    Very well explained, especially that this keyword in an arrow function uses the lexical this scope!

  • @enversecilmis7627
    @enversecilmis7627 Год назад +1

    I finally understand this. Thank you!

  • @poornachandra4816
    @poornachandra4816 Год назад

    how it behave when we use arrow function as method inside objection , please cover on this

  • @ektabansal7645
    @ektabansal7645 Месяц назад

    const address={
    name:"Peter",
    age: 26,
    something: () => {
    return this.innerHeight;
    }
    }
    console.log(address.something())
    why this arrow function is referring 'this' as window object, when its parent scope is the address object? Can you please explain

    • @ektabansal7645
      @ektabansal7645 Месяц назад

      ok, i got this. as per your definition, arrow function takes the scope of its parent, now the scope of its parent(address object) is global scope as address object can be used in the global code, that could be the reason for this behaivour, Please correct me if my understanding is wrong

  • @TusharBorawake
    @TusharBorawake 3 года назад

    If we make calcAge as a arrow function & we call like John.calcAge() then what will 'this' point to ? John object or window object?...

    • @procademy
      @procademy  3 года назад +4

      If you are defining calcAge function inside John object, and if the calcAge function is an arrow function, then the this keyword inside that arrow function will point to global window object
      But, if the arrow function is defined inside a regular function, and that regular function is defined inside John object, in that case, this keyword in regular function will point to John object. And in turn, this keyword inside arrow function will also point to John object. Why? Because in arrow function, this keyword points to its immidiate sorrounding this keyword. In this case the immidiate sorrounding this is pointing to John object.
      Hope it make sense.

    • @TusharBorawake
      @TusharBorawake 3 года назад +1

      @@procademy thanks for clarification...I am glad and feel blessed to found such knowledgeable and informative channel on RUclips. Every developer should watch all J's watchlist.so beautifully explained. Thanks again for sharing with us.❤️🧡💛

    • @procademy
      @procademy  3 года назад +1

      Please share this channel with others if you like my videos...🤝🤝

    • @TusharBorawake
      @TusharBorawake 3 года назад

      @@procademy sure