Understanding this Keyword in Different Contexts in Javascript


this refers to different objects depending on the context.

Source Code

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

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