Javascript Interview Questions ( 'this' Keyword ) - Output Based, Scope, Implicit Binding, etc

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

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

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

    🔴 Get my Complete Frontend Interview Prep course - roadsidecoder.com/course-details

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

      Hii brother can I get to know what's your age ??

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

      @@Solo_playz 24

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

      @@RoadsideCoder Great man are you an IITian

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

      @@Solo_playz No, I'm from a tier 3 college

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

      @@RoadsideCoder What is tier 3 ??

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

    You are an absolute genius, i never understood this concept but your teaching is just fabulous, i hope that you launch your own udemy course in a structured way to master JS. You deserve to get paid for such content

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

    this is some excellent practice material. pls add more o/p based Qs for OOJS, Prototypes, etc.
    an addition to the problem at 17:25 -
    if at line 4, we use let/ const instead of var to create 'length' variable, then while executing 'callback', the (this) Window object won't have length set to 4. It could be anything, like in JSFiddle, it is set to 0. since let/ const are created in TDZ.
    there can be so many more variations to this problem. i find this an incredible practice problem. many thanks!

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

    Great explanation! A more accurate answer would be :
    In an arrow function "this" is a part of its closure, i.e. it is taken from the context. Where it is defined and not the object in which it is defined.
    In a normal function "this" is points to the object it is a part of.

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

    this channel is highly addicted,i have seen more than 10 videos continously

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

      Hahah good to know ❤️

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

      @@RoadsideCoder you are awesome😎

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

    This is some really high quality content and all for free! Your curation of questions are impressive, really making me scratch my head. Thank you mate!

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

      Thanks man! Full course here - roadsidecoder.com/course-details

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

      @@RoadsideCoder For sure. I'll buy your courses the first thing I get a job lol. Also do you have a patreon.

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

    I havent seen more detailed videos on coding subjects than yours! Thank you!

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

    This series is Onepiece of Javascript

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

    I know it is a generalization, but many Indian devs seem to have issues with following naming best practices and I can't figure out why that is...On a more serious note, great videos, well structured and researched.

    • @de-stressmusic432
      @de-stressmusic432 2 ปีที่แล้ว +3

      This is because the whole video is a copy of an article by dmitripavlutin, my previous comment mentioning it was deleted.

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

      @@de-stressmusic432 Its was helpful to have a written article

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

    At 14:50 we can do "setTimeout(user.logMessage(), 1000);", its giving correct output. We can do this also "
    setTimeout(user.logMessage.bind(user), 1000);"

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

    Just learned so many new things from this video. The last ques is just amazing. Please make more such video of questions like the last one. Highly informative content 👌✌

  • @front-end-world
    @front-end-world 9 หลายเดือนก่อน

    I was recently asked a question on what is the difference between invoking the object directly suing the method & using call
    I did not know this implicit bindings vs explicit binding
    Great one kudos piyush :)

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

    Extremely helpful video! Helped me to develop a more clear understanding of 'this' keyword . Please keep on making more such output based questions videos.

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

      Yes, So many more on the way!

  • @MukeshKumar-bt5gb
    @MukeshKumar-bt5gb 2 ปีที่แล้ว +2

    Thanks, Was waiting for this!
    I was asked many questions regarding this in Cars24 interview this week 😄

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

    Thanks Piyush, your roadside coding clears so many doubts related to "this" 🤟🙏🙏

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

      Glad to hear that

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

    I absolutely LOVE your videos. You are amazing at explaining everything and for the first time EVER, I finally get it! Thank you. Do you have patreon? I'd love to support you.

  • @abhishekkumar-ot4zo
    @abhishekkumar-ot4zo หลายเดือนก่อน

    4:06 this keyword in a function with in an object points to the object
    4:43 this keyword in a function with in a nested object points to the nested object

  • @dhananjaygupta8554
    @dhananjaygupta8554 3 หลายเดือนก่อน +1

    This is blowing my mind 😮

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

      full playlist here - th-cam.com/play/PLKhlp2qtUcSaCVJEt4ogEFs6I41pNnMU5.html&si=wrbL8KA4a4fxHNRN

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

    Bhai Apka Knowledge toh kamal ka hai🖤🖤🖤

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

    Unbelievable video! I like all your Playlist about react and javascript...
    Love from indonesian 👍

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

    Question 6 & 7 are just mind blowing.

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

    You are splendid

  • @SonuKumar-tw1oi
    @SonuKumar-tw1oi ปีที่แล้ว

    Please make a video on class , and its relation with this...Your content and teaching is fabulous.

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

    Great video! Are you going to drop some videos related to OOP Concepts(constructor, class) or Prototype Inheritance?

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

      Yes, definitely if more people ask for it!

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

      @@RoadsideCoder pls do it , then more people will watch and subscribe like me

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

      @@RoadsideCoder yes sir..I also interested. After that can you explain about promise from scratch.

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

      @@RoadsideCoder yes please drop a video brother

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

      @@RoadsideCoder yes, need some good videos on OOP concepts

  • @shubhamkharadkar3753
    @shubhamkharadkar3753 7 หลายเดือนก่อน +1

    00:02 Understanding 'this' keyword in JavaScript
    02:11 Understanding 'this' keyword in different contexts
    04:14 Understanding 'this' keyword in JavaScript
    06:32 Understanding 'this' keyword in normal function and arrow function
    08:41 Understanding 'this' keyword in JavaScript object
    10:37 Accessing 'this' inside a function can be tricky.
    12:42 Understanding 'this' keyword in JavaScript
    14:49 Understanding 'this' keyword in different functions
    16:50 Understanding 'this' binding in JavaScript.
    18:38 Understanding 'this' keyword in JavaScript functions
    20:40 Example of chaining functions in JavaScript
    22:32 Upcoming video on Explicit Binding

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

    Thank you Piyush, great explanations as always.

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

    13:50 logs name when we use parenthesis in front logMessage method invocation.... Or if you set user property using let keyword

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

    fact is `this` is the least thing we will ever gonna use (class based is exception) in our day to day work, this makes this concept tougher but interviewers love this type of question lol😆, btw Awesome video 🔥

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

      That's not true, if your company is using let's say class based component in react, it will use 'this' a lot

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

      @@RoadsideCoder Completely agree forget about class based ✌but we're shifting towards functional based programming 😌

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

    Hi Dear… I am really a big fan… You have such a deep knowledge of almost every technology. I have 1 request… Do you have any idea about how can we call salesforce commerce cloud API from Angular??? please reply if you know this or make a short video. Thanks

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

    this was great..can you please make videos on node,express,mongo too. That would be extremely helpful since you explain things quite nicely.

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

    THIS IS GOLD

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

    this with arrow function is greatly explained. thank you

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

    for all the viewers i give the golden rule
    * object don't create binding with this function do in js
    for e.g
    let obj = {
    name:"steve",
    valueOfthis:this,
    arrowFn:()=>this,
    normalFn:function(){
    return this
    }
    }
    here valueOfthis and arrowFn always gives window why because object don't create binding with this and arrow function also not create binding with this whereas normalFunction create binding with this
    hope this explanation work 😀😀

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

    thank you because of you I understand this

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

      Thanks, u can check the complete course here - roadsidecoder.com/course-details

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

    Great video bro! Keep coming up with interesting videos like these ❤️.
    Just adding one more concept here Arguments in a function is not an array it is array like object.
    Array like object does not have all the properties of an array like map, filter etc.

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

      Thanks for this important detail

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

    Thank you so much!
    This is so informative 💖

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

    Thank you so much! You're my favorite teacher.

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

    Yes we want video on class,new keyword , etc....

  • @AmirHussain-dd6zw
    @AmirHussain-dd6zw 2 ปีที่แล้ว

    You have great variety of questions

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

    gem of explanation ...thank you

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

    I love this

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

    Hey Piyush, thanks for this awesome video. Please correct my understanding if I am wrong:
    print is defined inside obj and obj don’t have its own scope its inheriting the scope from its parent which is global object that’s why arrow function pointing to global object (bcz it inherits this from lexical scope) .
    let obj = {
    name : 'temp',
    print : () => {
    console.log(this); // global/window object
    }
    }

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

      It doesn't matter what scope obj has, arrow function takes its scope from parent normal function which in this case is not there, so it is targeting global. So even if the arrow function nested deep inside a object, if it doesn't have a parent normal function, it act the same.

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

      @@RoadsideCoder Ok got it, arrow function search for nearest regular function that encloses it but in this case its not enclosed by any regular function then global this is inherited by arrow function.

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

      @@jayantsharma2669 Yes!

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

    Yes
    Please make video on class as well

  • @RahulKumar-ew1qw
    @RahulKumar-ew1qw 2 ปีที่แล้ว

    Bro u make me great than my yesterday.
    Thank you ...

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

      Great to hear that brother!

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

    thank you Roadside coder .

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

    Bro, your output based questions are Awsome.👋

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

    Question 5 was amazing! Thanks!

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

    My solution for Question 2:
    function user() {
    return {
    name: "Sajal",
    ref: this
    }
    }
    const test = user();
    const result = user.bind(test);
    console.log(result().ref.name); //Sajal
    I tried it with .bind() 😀

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

    This always sounds confusing. Just the easiest way to interpret. Its always the caller function for the normal function calls and for the arrow functions it will always be 2 level deeper( kind of like parent of parent)

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

    Great explanation!! Thanks

  • @Saikumar-kb4lf
    @Saikumar-kb4lf 2 ปีที่แล้ว

    This is really good content. I can't deny that. But definitely here 'this' was explained in a hacky way. Please watch this related video from dev sage and you can really master this

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

      Thanks, The main aim of this video is to assist for Javascript Interviews, therefore the hacky way.

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

    yes please make a video on constructors and this🙏

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

      You can find this and other topics here - roadsidecoder.com/course-details

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

    Amazing Video🥳

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

    Please continue this series

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

    on 17:56 the same code run on browser and node console return different result. on node console it return undefined?

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

    yes Please create a deep tutorial on class and constructor

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

    Awesome👍👍👍

  • @GopalAkkar-h9b
    @GopalAkkar-h9b ปีที่แล้ว

    Can you add interview series for Angular ? It will be really helpful for us as angular developer.

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

    bro what's your approach for learning these type of concepts in depth?

  • @VivekG-e1o
    @VivekG-e1o ปีที่แล้ว

    Please make a video on session and local storage with Json.stringify , parse , constructors and classes also.

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

    Dude just got introduced to your channela few days back your content is amazing, keep going man!!

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

      Welcome aboard! And thanks a lot. ❤️

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

    Amazing Video's ♥️

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

    Thank you so much..amazing content.

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

    Can you please help expain in 18:02? Why the nested fn() is targeted the global window object? Thanks!

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

      watch my functions video, u will understand it

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

    Helpful!! , thank you ❤

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

    Great video as always. Btw you are saying and spelling “substract” instead of “subtract”

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

    Please release next vedio on bindings as soon as possible.

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

    Supep video

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

    Really good content, make some practice platform

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

    Please tell the references point from where you learned all the core concepts of javascript

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

    Piyush please create video on class, prototype inheritance, and new feature of javascript

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

    Thank you

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

    Have you come across any practice sites that help us sharpen these skills?

  • @RavindraSingh-lp9pl
    @RavindraSingh-lp9pl 11 หลายเดือนก่อน

    please make video on class and constructor in Javascript

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

    Video on class and constructors please!!

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

    14:08 piyush, can we do bind as well here? because I think once we bind a method with a object, no matter when/where we call that function it will always point to that object.

  • @neeraj-u6e
    @neeraj-u6e 2 ปีที่แล้ว

    Make video for everything in javaScript ..

  • @0Ipsita0
    @0Ipsita0 ปีที่แล้ว

    Make video on class, constructors video please, i don't understand those

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

    sir what is window object and global object?
    plz explain a bit..

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

      Hey, you can refer to this - developer.mozilla.org/en-US/docs/Web/API/Window

  • @ShivamSingh-ct1ix
    @ShivamSingh-ct1ix ปีที่แล้ว

    Hello Can you make a video on OOPS concept in javascript.

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

    Bro why dont you create javascript vedios on basic data structure algorithm so it will help in interviews.

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

      Yes I have planning that, coming soon!

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

    where we can practice all those types of question ?

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

    So What' difference if you upload same video in your paid course and and youtube ?

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

      Here's your answer - www.linkedin.com/feed/update/urn:li:activity:7174019126041018370/?originTrackingId=GTshFzTMQBqFiLZrQQuBNw%3D%3D

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

    let user = {
    name :"hema mane!",
    getName(){
    console.log(this.name)
    }
    }
    let data =setTimeout(
    user.getName()
    ,1000)
    console.log(data)
    console.log(data) ---> is it correct way of accessing or else mandetory to use inside function only

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

    You should title these videos "JS trick questions". Seriously, if an interviewer was to ask these sorts of questions I'd politely excuse myself and look elsewhere.

  • @PIYUSH-lz1zq
    @PIYUSH-lz1zq 2 ปีที่แล้ว

    sir , can u make videos to make nested comment section and folder structure using JS

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

    please make oops concept on javascript in details

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

    Nice.

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

    Why calling user.method() inside console.log is not called as callback??

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

    can you make a video of stripe payment plzzzzzzzzzzzz in hindi

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

    this.a=7;
    function test(){
    console.log(this.a);
    }
    test() result is showing undefined

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

    hey ,
    where can we find these kind of other questions

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

    Q3. it should be setTimeout(user.logMassage(), 1000) //() missing

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

    var length =4;
    function callback(){
    console.log(this.length);
    }
    const object ={
    length :5,
    method(fn){
    fn();
    },
    };
    object.method(callback);
    it giving undefined instead of output 4 anyone?

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

      Ya facing the same issue

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

    you go boy!!!!❤️❤️

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

    The day this video got published i was asked the calc question and i messed up because of 'this' reference

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

    make a video class and constructor

  • @PIYUSH-lz1zq
    @PIYUSH-lz1zq 2 ปีที่แล้ว

    bhaiya , make a small js project which consist of these js concepts of debouncing , throttling etc.. placements r comming

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

    Hey guys .. can anyone explain why window.ref.name is not undefined and it is empty?

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

    Where to get all these questions?

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

      All questions are from here dmitripavlutin.com/javascript-this-interview-questions/

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

      @@samyakjain9850 thanks man