DEV Community

Discussion on: 70 JavaScript Interview Questions

Collapse
 
greatgraphicdesign profile image
Alek Vila

Regarding Question 24, I want to really understand "this" so I tested each example in the Console. I found a different result than what you shared for this line...

myFavoriteObj.guessThis();

You wrote that it logs the window object; however, I'm seeing that in normal mode it logs nothing and in strict mode it throws an error. Maybe it is working differently on your browser? I'm using Chrome 81 on Mac.

By the way, I am enjoying studying this post. Thank you!

Collapse
 
macmacky profile image
Mark Abeto

Thanks, for finding my mistake. I edited it just now. No problem man, glad you like it.

Collapse
 
greatgraphicdesign profile image
Alek Vila

Believe it or not, I'm still going through your list and taking notes. This is a very cool post.

By the way, I've cleared my browser cache the graphic is the same. Maybe it's cached on the server side?

Thread Thread
 
macmacky profile image
Mark Abeto

I've changed the object.

It looks like this now.

 const myFavoriteObj = {
     guessThis(){
        function getThis(){
          console.log(this);
        }
        getThis();
     },
     name: 'Marko Polo',
     thisIsAnnoying(callback){
       callback();
     }
   };


`

Thanks

Thread Thread
 
greatgraphicdesign profile image
Alek Vila

Ah, I see the change now. You removed .name from where it used to say console.log(this.name); Thank you!

Thread Thread
 
macmacky profile image
Mark Abeto

Your welcome. Thanks, again for finding my mistake.

Thread Thread
 
kuncheriakuruvilla profile image
Kuncheria Kuruvilla • Edited

Hey , even now i think there is a problem.
Shouldn't it be
this.name = "Ford Ranger";

rather than
var name = "Ford Ranger";

for question number 24 ?