Understanding this Keyword in Different Contexts in Javascript


The value of this varies based on the context in which it’s used.

Source Code

function show() {
  console.log(this);
}
show(); // logs global object or undefined in strict mode

let obj = {
  show: function() {
    console.log(this);
  }
};
obj.show(); // logs obj
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments