Rafique Ahmed
Rafique Ahmed

Reputation: 117

How does use strict impact this keyword in the context of call and apply method of a Function object in Javascript ES5 and ES6

I want know the concept of this in use strict mode , in the context of call and apply method of a Function object in Javascript ES5 and ES6. A good example with explanation will be highly appreciated.

Upvotes: 0

Views: 53

Answers (1)

Felix Kling
Felix Kling

Reputation: 816780

If a function is strict, its this value is not converted to an object but kept as it is. For non-strict functions, this is always converted to an object (unless it is null or undefined of course):

function foo() {
  console.log(typeof this);
}
function foo_strict() {
  "use strict";
  console.log(typeof this);
}

foo.call(42);
foo_strict.call(42);

Upvotes: 3

Related Questions