JavaScript this keyword binding in arrow functions

This JavaScript question trips up  even experienced developers. What's the output? 👇 const obj = {  name: "Shivesh",  greet: function() {   console.log(this.name)  },  greetArrow: () => {   console.log(this.name)  } } obj.greet()   // ? obj.greetArrow() // ? Drop your answer in comments  BEFORE scrolling! 👇 I'll reveal the explanation  in the first comment! #JavaScript #Frontend #WebDevelopment #CodingInterview #JSInterview #ReactJS

  • graphical user interface

Answer: obj.greet() // "Shivesh" ✅ obj.greetArrow() // undefined Arrow functions don't have their own 'this' — they inherit from lexical scope. How many got it right? 😊

Like
Reply

To view or add a comment, sign in

Explore content categories