JavaScript Function Invocation Context

🚨 JavaScript Interview Question What will be the output? const obj = { name: "Frontend", greet: function () { console.log(this.name); } }; const greet = obj.greet; greet(); greet.call(obj); greet.bind(obj)(); This question tests understanding of: • this binding • call() • bind() • Function invocation context Many developers expect all three calls to behave the same. But JavaScript handles this differently depending on how the function is invoked. What do you think the output will be? #JavaScript #FrontendInterview #ReactJS #FrontendDeveloper #JavaScriptConcepts #ProductBasedCompany

Hint: call() invokes the function immediately with a specified this, while bind() returns a new function with this permanently bound.

Like
Reply

Frontend Frontend function() { Console. Log(this.name)} Is this correct Suman Yadav

greet() undefined (or error in strict mode) greet.call(obj) Frontend greet.bind(obj)() Frontend

Like
Reply

undefined Frontend Frontend

Like
Reply

Undefined Frontend Frontend

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories