What is THIS in JavaScript? 👈

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

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

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

    // this = reference to the object where THIS is used
    // (the object depends on the immediate context)
    const person1 = {
    name: "Spongebob",
    favFood: "hamburgers",
    sayHello: function(){console.log(`Hi! I am ${this.favFood}`)},
    eat: function(){console.log(`${this.name} is eating ${this.favFood}`)}
    }
    const person2 = {
    name: "Patrick",
    favFood: "pizza",
    sayHello: function(){console.log(`Hi! I am ${this.favFood}`)},
    eat: function(){console.log(`${this.name} is eating ${this.favFood}`)}
    }
    person1.eat();
    person2.eat();

    • @professorpoke
      @professorpoke 5 หลายเดือนก่อน

      Are you github ?

  • @Devanshugoel
    @Devanshugoel ปีที่แล้ว +19

    was struggling with THIS keyword you cleared it in just 5 min dude you are one of the best teacher on youtube

    • @helioobianchi
      @helioobianchi 10 หลายเดือนก่อน +1

      I've seen people saying it's pretty easy to get confused with which object 'this' is referring to. I haven't learned enough to know good JS practices, but it's good to keep it in mind so I know I need to learn this at some point

  • @als4515
    @als4515 ปีที่แล้ว +12

    Hands down, best programming instructor on TH-cam. Simple and clean explanations.

  • @sunkorg
    @sunkorg ปีที่แล้ว +17

    This is great! Can you explain in more detail in a later video on why arrow functions don't recognize "this?" I understand it has to do with scope, but I'm not quite wrapping my head around how arrow functions handle scope differently. Thanks again for your time and expertise sharing this!

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

    hands-down this is the best & shortest explanation for this keyword

  • @orderla8877
    @orderla8877 11 หลายเดือนก่อน +3

    Bro just "de-obfuscated" my mind.
    Appreciated and subscribed.

  • @nickyrenz
    @nickyrenz 5 หลายเดือนก่อน

    I was struggling with the 'this' keyword a bit as a novice programmer, but this video made it clear as day. Thank you so much!

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

    Actually, I was searching for this content. It's really helped me.
    Thank you so much❤

  • @joeviloria3409
    @joeviloria3409 9 หลายเดือนก่อน

    Your videos are amazing! To the point, clear, well illustrated. It has helped me grasp a few concepts better.

  • @abdulsamadkhan5552
    @abdulsamadkhan5552 3 หลายเดือนก่อน

    by far the greatest code learning channel I have seen 🙇‍♂🙏🙏🙏🔥🔥🔥🔥

  • @lakornhouse9855
    @lakornhouse9855 5 หลายเดือนก่อน

    Woww, struggling it for hours. But you made me understand about it within 4-5 min? Bro, amazing!! Thank you so much!

  • @amw7654
    @amw7654 5 หลายเดือนก่อน +3

    The "Hi, I am hamburgers" 😂

  • @adriatic101
    @adriatic101 3 หลายเดือนก่อน

    finally understood it, thanks man

  • @EliasVargas-v7e
    @EliasVargas-v7e 6 หลายเดือนก่อน

    God bless you and the day you decided that you wanted to open a TH-cam channel man

  • @arix2259
    @arix2259 3 หลายเดือนก่อน

    Man you are just Awesome!!!!!!!!!!!

  • @ashishdhal4614
    @ashishdhal4614 5 หลายเดือนก่อน

    Brother you a saviour 😭😭

  • @piotrmazgaj
    @piotrmazgaj 5 หลายเดือนก่อน

    This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal.

  • @اخت-ط3ع
    @اخت-ط3ع 4 หลายเดือนก่อน

    THANK YOU.

  • @yuvrajsingh-fz7hd
    @yuvrajsingh-fz7hd 5 หลายเดือนก่อน

    bro how do u have time to watch all these cartoons like in another video of yours i saw an example of pokemons and it was like that u know and follow pokemon till date, whereas i do coding all day like 10hrs per day but how do u have so much time 😭😭 btw love your teaching style u make everything look so easy thanks a lot man

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

    will you be my mentor :), on my way to learn full stact(MERN) development.

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

    since it is the same as writing the name of the object, is this keyword used in case there are nameless things? or so that you can use the same code for different objects since it automatically updates the object name in the method? Thanks so much bro, even if you don't answer, I know you've got work to do ❤

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

    We need more React content :((

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

    My Bro, why you are not making android development tutorial???????????☺☺☺☺☺☺☺☺☺

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

    goat

  • @GauravPhoju
    @GauravPhoju 4 หลายเดือนก่อน

    I was playing around with the arrow function for 2 minute and gave up... Only for my Sensei to mention it doesn't work in the end

  • @helioobianchi
    @helioobianchi 10 หลายเดือนก่อน

    I still feel confused with those different ways of writing functions. What are the differences between them? why doesn't the arrow function refer to the object in which it was written when using 'this'?

  • @ali_thegamer981
    @ali_thegamer981 23 วันที่ผ่านมา

    yes bro we can't use this keyword in arrow function but we can use this keyword in setTimeout and setInterval function.

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

    What does it think 'name' is if it's not 'this.name'?
    EDIT: Oh is it because everything inside the function is inside the local scope of the function and NOT the local scope of the object? Therefore the object key-values aren't passed into the function without 'this'?

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

    Thank you guys❤

  • @EduardoFernandes-y1v
    @EduardoFernandes-y1v 5 หลายเดือนก่อน

    Hi I am hamburgers

  • @MrUpaps-pp2tb
    @MrUpaps-pp2tb 3 หลายเดือนก่อน

    ohhhh now i know

  • @GoalDigger-footboll
    @GoalDigger-footboll 5 หลายเดือนก่อน

    this is keyword in jS??