What is THIS keyword in JavaScript? - Tutorial for beginners

Sdílet
Vložit
  • čas přidán 25. 06. 2024
  • What is the THIS keyword in JavaScript? How does it work and why is it so confusing?
    The THIS keyword, from the series "10 Things JS Developers Should Know"
    by ColorCode.io, Sina Jazayeri
    Full playlist here: • 20 Things JavaScript D...
    This is episode 6 in a 10 part series I’m calling 10 things javascript developers should know but probably don’t. In this series, we’re going to cover some of the most fundamental and important parts of JavaScript that most of us don’t actually know, and barely touch. Today, for episode 6, we’re talking about the THIS keyword, how context and execution logic changes the value of the this keyword, and how arrow functions affect the value? Episode 6: The THIS keyword. Let’s go!
    All the code from this series is available here:
    github.com/ColorCode/js-10-th...
    0:00:00 Intro
    0:00:53 THIS in Global scope
    0:01:40 THIS inside functions (methods)
    0:06:25 Function.bind
    0:10:03 Function.call
    0:16:10 Function.apply
    0:16:42 THIS inside Constructor functions
    0:20:00 THIS inside callback functions
    0:23:40 THIS inside arrow functions
    0:24:26 Conclusion

Komentáře • 277

  • @ColorCodeio
    @ColorCodeio  Před 3 lety +45

    JavaScript THIS keyword explained - A deep dive 👨🏻‍💻

    • @arod3295
      @arod3295 Před 3 lety +1

      So I have a very important question. PLEASE help. So there must be more to the layers of seniority I should say to the concept of front vs backend…there’s more job titled for a coder of all levels. What are those many titles called?
      Web developer
      Front end
      Back end
      Web designer
      Programmer (which idk if that’s just another word for web dev or if that’s a proper title)
      Junior developer (idk if that’s another word for entry front end)
      What other titles are there? Knowing this would help people find a proper path to get started instead of aiming high like “I want to be a software developer” like I did 3yrs ago. Now I’m aiming for front end (if that’s right) and design web logic to interact with smart contracts (I want to work in the blockchain industry and a lot of the work is programming websites to interact with the contracts)
      Thank you

    • @starkxz
      @starkxz Před rokem

      @@arod3295
      There are many job titles and roles within the world of software development. Here are some common ones:
      Full-stack developer: a developer who can work on both the front-end and back-end of an application.
      Mobile developer: a developer who specializes in building applications for mobile devices.
      Game developer: a developer who specializes in building video games.
      DevOps engineer: a developer who works on the development and deployment of software through collaboration with software developers and IT professionals.
      Software engineer: a developer who designs, builds, and tests software applications.
      QA engineer: a developer who is responsible for testing software applications to ensure that they function properly.
      UX/UI designer: a designer who specializes in creating user interfaces and experiences for software applications.
      Product manager: a professional who oversees the development and management of a software product.
      Technical writer: a professional who creates documentation and user guides for software applications.
      It's important to note that some of these roles may require more specialized knowledge or experience in a particular area. For example, becoming a mobile developer may require knowledge of specific programming languages and frameworks, as well as experience with mobile app development.
      Ultimately, the best way to determine which role is right for you is to explore the different areas of software development and see which ones interest you the most. Consider taking online courses or tutorials, attending meetups or conferences, and talking to professionals in the field to learn more about the different roles and how you can get started in your desired career path.

  • @cleanocavalcante
    @cleanocavalcante Před 2 lety +77

    Dear CZcams's Algorithm gods, please bless this channel with a million views per episode 🙏🏼😁. This content is absolutely gold. I've been learning JS for the past 2 months and I'm really benefitting from all this knowledge. Thank you so much, and keep up the fantastic work! Cheers from Brazil!

    • @ColorCodeio
      @ColorCodeio  Před 2 lety +10

      Haha this is the best comment I ever got. Thank you. I'm glad these videos are helping. Message me on instagram if you have questions.

    • @cleanocavalcante
      @cleanocavalcante Před 2 lety +1

      @@ColorCodeio You 100% deserve it!

    • @omersoncruz1081
      @omersoncruz1081 Před rokem

      Amen!

    • @uzgurCoder
      @uzgurCoder Před 10 měsíci +1

      Your wish granted😁😅😅

  • @darksoulgamer5837
    @darksoulgamer5837 Před 2 lety +45

    This is an underrated channel! The explanation is mind blowing not confusing at all, please keep making videos on JS 🙏

    • @ColorCodeio
      @ColorCodeio  Před 2 lety +4

      Great to hear that! More videos coming soon.

    • @redeye8536
      @redeye8536 Před 16 dny

      @@ColorCodeio lol i really like this thank you lolllll xddddd

  • @atlas8133
    @atlas8133 Před 2 lety +14

    'This' video should have at least 100 times more views. Pure gold if you've ever been confused about the intricate applications of 'this' in different contexts. He also covers .bind, .call, .apply as a nice bonus. My favorite video about 'this', simple as 'that'!

  • @axkongkong2819
    @axkongkong2819 Před rokem +4

    I watched your video on THIS...didn't understand anything......then i watched 10 other random videos on CZcams about THIS....did not understand anything. I gave up and went on with my day. The next day your 1 min video on THIS popped up, i watched that, and that was clear as day!!!! I followed up by watching this 24 min video, and everything was so clear!! I don't know if its just the time it took for information to absorb over 24 hours or i re-watched your videos a few times like you said at the end, in order to get it. One thing is for sure, this is the best tutorial on THIS and i am pretty sure i watched them all. Love your teaching style, very good examples and slight humor sprinkled around. Subscribed!

    • @ColorCodeio
      @ColorCodeio  Před rokem +1

      That's awesome! Thanks for sharing and I'm glad it clicked.

  • @RossieeissoR
    @RossieeissoR Před 2 lety +4

    Style, pace, music, explanation, effects, even typing sound... everything is perfect.

  • @Flipping_myFinds
    @Flipping_myFinds Před 3 lety +4

    Always liked creating and designing. Programming is a new journey that I’m taking (haven’t had really good inexpensive sources to learn from)and I’m super glad I found you and I know your videos and courses will guide me finally the right way

    • @ColorCodeio
      @ColorCodeio  Před 3 lety +2

      Great to hear! Best of luck in your journey and reach out to me if you have questions.

  • @digitalfragrant
    @digitalfragrant Před 3 měsíci +2

    The most underrated educator on YT. Production quality is also insane. Keep it up man!

  • @prakharpaw-de7vh
    @prakharpaw-de7vh Před rokem +1

    came here looking for explanation on the original f***ing a**hole of JavaScript, aka the this keyword. Ended up watching the entire series.
    Thank you

  • @salamina_
    @salamina_ Před 2 lety +1

    Excellent explanations on subjects have always been a mystery to me. Thank you for making these tutorials, really insightful and entertaining.. dig your teaching
    style. Keep them coming!

  • @asadmoosvi
    @asadmoosvi Před 2 lety +4

    Love these videos! You explain concepts really well and in great detail.

  • @dipankarsahoo7119
    @dipankarsahoo7119 Před rokem +1

    i watched a single video of yours and fell in love with your way of teaching, the background music, the humor everything loved it ..! subscribed

  • @myashkov1975
    @myashkov1975 Před rokem +1

    Simple, clear and perfect for beginners explanation of 'this' keyword, thanks, man!

  • @starkxz
    @starkxz Před rokem +1

    This channel is the best when it comes to JS. Honestly it needs more views. Thanks Sina, keep up the fantastic work.

  • @neria15
    @neria15 Před 5 měsíci +1

    this playlist need to be everywhere !
    Thank you Sina!

  • @kurisu26
    @kurisu26 Před 8 měsíci

    Best "this" tutorial I found. Thanks

  • @Fred-my9er
    @Fred-my9er Před rokem +1

    This was so well explained with good examples. I probably need to rewatch it to remember everything but I understood it all.

  • @syedaun5410
    @syedaun5410 Před 2 lety +1

    Please keep going with your videos.
    You are really easy to understand and fun to watch.

  • @nnex5
    @nnex5 Před rokem +1

    This channel and Web Dev Simplified are the most helpful channels for Web Developers. Thank you!

  • @ebcoutinho
    @ebcoutinho Před 4 měsíci +1

    These videos are helping me to fill the knowledge gaps I have

  • @towhid6476
    @towhid6476 Před rokem +1

    Loved the video explanation. I was following a JS course for a month and this one dominates all

  • @jatilyadav4000
    @jatilyadav4000 Před rokem +1

    Content is just amazing I could'nt stop watching

  • @alainkaiser2697
    @alainkaiser2697 Před 10 měsíci +1

    this is better than 99% of the blog posts out there trying to explain core concepts like this!

  • @user-vv5kw1ku2q
    @user-vv5kw1ku2q Před 5 měsíci

    What a great job, you're doing!

  • @irenashovel9244
    @irenashovel9244 Před rokem

    this is amazing! thank you so much for this deep dive!

  • @stepanterechshenko5435
    @stepanterechshenko5435 Před rokem +1

    best explanation of "this" I have found and I was looking in 3 different languages on YT

  • @chrismills5307
    @chrismills5307 Před 8 měsíci +1

    Amazing video, clear explanation, great communication and presentation skills, and covers all the ins and outs without making it overly complex.

  • @nynzxoxo
    @nynzxoxo Před 3 lety +3

    You deserve so many more views and subs! This content is gold

  • @namanjoshi5089
    @namanjoshi5089 Před 10 měsíci

    gold mine which isn't known by many .. love this channel

  • @RAJVEERBIRADAR360
    @RAJVEERBIRADAR360 Před 25 dny +1

    i was confused in this from aproximately 1yr i was just asuming it not understanding it true meaninig. thanks to you i was completely able to understand the topic this, (same concept self in python)

  • @MarstonH
    @MarstonH Před 9 měsíci +1

    dude you are so real and good at explaining. this has helped a lot

  • @TheAmanpro
    @TheAmanpro Před 2 lety +1

    Thank you so much! Beautifully explained. Keep posting

    • @ColorCodeio
      @ColorCodeio  Před 2 lety

      Thank you, Aman :) More coming next week.

  • @HarelYeh...
    @HarelYeh... Před 9 měsíci +1

    Really thanks for all the effort, it's really fun to watch and learn from you, you convey it in a pleasant way and not like a robot or excessive seriousness, just a pleasure.

  • @erickchavez4551
    @erickchavez4551 Před 11 měsíci

    Nicely explained! thanks for the amazing quality of your videos. Took a bunch of notes to review after watching the video.

  • @stevecrabtree9141
    @stevecrabtree9141 Před rokem +1

    Just found your channel, you would be a blast to work with! I would be dying all day with your humor

  • @user-kn4oi9oh4i
    @user-kn4oi9oh4i Před 3 měsíci

    Best explanation! I swear to god, this is amazing

  • @abhijeetbajpai1022
    @abhijeetbajpai1022 Před 5 měsíci +1

    Dude, I really love the way of teach things, Really Awesome !! The hat's off to you.

  • @thiagoneves50
    @thiagoneves50 Před 2 lety +2

    This is really good! I'm very grateful!

  • @BHASKARARAOKONNA
    @BHASKARARAOKONNA Před rokem

    Your explanation and presentation of the video are so good that I couldn't even wait to share this to my fellow learners and also SUBSCRIBED. Really, you should have got more views and subscribers. Keep up the good work 😀😎🙏

  • @taunado
    @taunado Před rokem +1

    Great production and all, thanks for sharing. +1 for providing purposeful and real-world use-case cases to provide the context for your teaching. My brain is constantly trying to work out the end goal and why what you're teaching has value, making it difficult to follow along.

  • @michaelnorton9715
    @michaelnorton9715 Před 8 měsíci

    Our WDD 330 Fundamentals of Web Development class at Brigham Young University - Idaho has this video as part of our notes! I like how you explained all of "this" ;) I enjoyed your video start and your energy throughout the video. I got lost on that last part where you set a time-out but I felt like I understand how to use "this" better than I did before. I need to watch your arrow function video. That's one thing that I get tripped up with. Thanks for all the time and work you put into making this video. Liked and subscribed!

  • @slaincore
    @slaincore Před rokem +1

    You are just awesome explainer/teacher! Keep going my friend!

  • @ivo_sa
    @ivo_sa Před 6 měsíci +2

    man, i love your videos ! they are incredibly informative and also funny to watch !

  • @steelmantv
    @steelmantv Před rokem

    Thank you! So helpful

  • @pushkarkumar5578
    @pushkarkumar5578 Před rokem

    love you man great work.

  • @error0803
    @error0803 Před 2 lety +1

    Very good and very high quality video. Thank you. Learned a lot👍🏻

  • @PatelBhaveshgo4glory
    @PatelBhaveshgo4glory Před 2 lety +1

    Amazing explanation. Keep it up, sir!

  • @MishraXE
    @MishraXE Před rokem

    The best explanation of This 😍

  • @uncoding_with_raj
    @uncoding_with_raj Před rokem +1

    Amazing tutorial man.

  • @himanshuarora1910
    @himanshuarora1910 Před rokem +1

    i really liked it when i can see the person who is teaching ,great work

  • @dineshreddy8915
    @dineshreddy8915 Před rokem +1

    perfect, everything is perfect....
    The concept , the video, editing , making us attracted, every thing is perfect
    expecting more video from you (react if possible)

  • @havefun5519
    @havefun5519 Před rokem +1

    Cool explanation. BTW, the video quality is great, and the speed of the talk is good, like the clear accent.

  • @programmingforfun4158

    I dont know how this type of content can only have 25k views

  • @IlPandax
    @IlPandax Před 4 měsíci +1

    As an italian brother, your italian is perfect! And also your Javascript! XD

  • @santhoshk9285
    @santhoshk9285 Před 3 lety +2

    keep rocking saanaaaaaaaa ... waiting for more 🔥

  • @YeetYeetYe
    @YeetYeetYe Před rokem +2

    Great editing.

  • @ann_uken
    @ann_uken Před rokem +1

    Thank you for the video, very well explained! 💥

  • @jimkk159
    @jimkk159 Před rokem +1

    So good, help me a lot!!

  • @nathalianobrega6917
    @nathalianobrega6917 Před 2 lety +1

    this is such a great video, thanks!

  • @sudiptasaha8905
    @sudiptasaha8905 Před rokem +1

    Hey, your content really adds value to my skillset. Please do make more videos. Love from India ❤

  • @andresfelipeladinoespitia
    @andresfelipeladinoespitia Před 9 měsíci +1

    Thank you very much man. I had to watch it a couple of times, but I finally got the whole *this* concept. Also, you sound 100% like Edward Snowden.

  • @oneofone_1333
    @oneofone_1333 Před 2 lety +1

    Man i stubbled on your content, love it!!!! Greetings from Switzerland

  • @yarinvanzikri
    @yarinvanzikri Před 2 lety +1

    love your content and attitude! am here just to say thanks!

  • @ayushdixit8993
    @ayushdixit8993 Před rokem +1

    You are great man!!!!!!!... Very well explained....
    Thanks

  • @user-lp5tk8tp6e
    @user-lp5tk8tp6e Před 10 měsíci +1

    Thank you very much:) love your sense of humor;)

  • @user-mw5bm2xh9x
    @user-mw5bm2xh9x Před 7 měsíci +1

    good stuff. thanks

  • @surf2553
    @surf2553 Před rokem +1

    Yep, super helpful!

  • @tetianazhuchenko2182
    @tetianazhuchenko2182 Před rokem +1

    Your expectations are great 👍 Thanks

  • @edhead76
    @edhead76 Před 4 měsíci

    Is bind only used with the keyword 'this'? This is a great explanation, but I had to pause and rewind several times to grasp the concept more fully. Actually, to clarify, this is the BEST explanation I've come across, and I have been searching for the correct way to use 'this' for quite some time!

  • @aballahsameh3597
    @aballahsameh3597 Před rokem +1

    So cool!

  • @Genesis0_o
    @Genesis0_o Před 8 měsíci

    You're a Legend

  • @ayman3711
    @ayman3711 Před rokem

    great effort

  • @aoniatraxler6897
    @aoniatraxler6897 Před 2 lety +1

    This is awesome, thanks :)

  • @anuragsingh-ts3nb
    @anuragsingh-ts3nb Před 2 lety +1

    best instructor which u cannot even get on paid course, after watching this i became his big FAN!!😊

  • @X82oo781
    @X82oo781 Před 5 měsíci

    love this channel

  • @dream5.2
    @dream5.2 Před 10 měsíci

    'This' is too good. I'll never choose that

  • @randyafriansyah9340
    @randyafriansyah9340 Před rokem +1

    instant subscribe, this channel is really emazing

  • @chriskasatka2095
    @chriskasatka2095 Před 2 lety +1

    Amazing channel!

  • @taylorwade1537
    @taylorwade1537 Před rokem +1

    .this is awesome and THIS is awesome. Thank you so much!!

  • @user-vo8hn7yj7z
    @user-vo8hn7yj7z Před 10 měsíci

    Great explanation! By the way, what actually is the favorite feature mentioned in 2:54 ?

  • @darksoulgamer5837
    @darksoulgamer5837 Před 2 lety +2

    Love these videos, but could you also share some real world use cases? Like for call, apply,bind etc. Even for this, why do we really need it

  • @MuhammadUsman-fl7lo
    @MuhammadUsman-fl7lo Před rokem +1

    The channel needs more support !

  • @alirezarezaei7416
    @alirezarezaei7416 Před 2 lety +1

    Thanks a lot. after a lot of exhausting search, i realized this keyword.

  • @nathanisong9393
    @nathanisong9393 Před 2 lety +1

    I love how you interact even though I am not still cool with it yet. But thanks

  • @tonydaian8036
    @tonydaian8036 Před 2 lety +1

    Great content!

  • @Professor-eu1ll
    @Professor-eu1ll Před 11 měsíci +1

    2nd best channel after ColorCode. Oh wait this is ColorCode

  • @WaseemAbbas-lv5xm
    @WaseemAbbas-lv5xm Před 3 měsíci

    Awesome i love this course ❤ . Also make a tutorial on React

  • @by2313
    @by2313 Před 3 lety +3

    I really like your classes. I'm using them in conjunction with a UDemy course and learning it from a couple folks is helping it sink in a bit more. I hope you do one on the Reduce method.

    • @ColorCodeio
      @ColorCodeio  Před 3 lety +1

      Awesome. I may do one in August

    • @davidmmadden
      @davidmmadden Před 2 lety

      @@ColorCodeio would also love one on reduce!

  • @weiguo2297
    @weiguo2297 Před rokem +1

    Nice video. Help me to solve my confusion about the meaning of this in JSX callbacks.

  • @szanka96
    @szanka96 Před rokem +2

    I'm amazed that THIS can be explained without causing a headache. Hit the subscribe button. Thank you so much :)

  • @hunin27
    @hunin27 Před 7 měsíci +2

    you look like tony stark and i find it amazing

  • @longingbydesign
    @longingbydesign Před 3 lety +1

    Thank you for your amazing videos. Please consider dropping the use of the non-standard innerText in favor of the standard textContent as many of your less experienced viewers will pick up that otherwise. innerText has its place (preserving linebreaks and whitespace), but in your examples its really all about textContent.

    • @ColorCodeio
      @ColorCodeio  Před 3 lety +1

      Thanks for the comment. You obviously pay close attention to detail :)

  • @mohamedmahmoud-nj1uh
    @mohamedmahmoud-nj1uh Před 5 měsíci +1

    your videos are amazing , you give tricky tips when you code , in a smpile ways , please make it 100 things you might don't knoOoOoOow in JS

  • @TottiBln
    @TottiBln Před 2 lety +1

    Thank You!!! Greetings from Germany, Berlin!

  • @razzchaudhary9184
    @razzchaudhary9184 Před 3 lety +1

    Amazing !!

  • @hustle4902
    @hustle4902 Před 8 měsíci +1

    You will definitely go to heaven bro💯

  • @boooloool6039
    @boooloool6039 Před 2 lety +1

    Subscribed! because you said " i am qoli" amazingly 😀 and of course such a good video!

  • @HosseinBajan
    @HosseinBajan Před 14 dny +1

    آقا دمت گرم عالی بود ❤

  • @sharonh387
    @sharonh387 Před 3 měsíci +1

    Thanks!

  • @Chris2phaBrown
    @Chris2phaBrown Před 3 lety +2

    Looking forward to the arrow function gotchas