Categories
Uncategorized

JavaScript Scope Example

const x = {
 a: 1,
 b: function() {
   console.log(this);
 }
}
x.b() /// {a: 1, b: ƒ}
const z = x.b   // here this is window
z() // undefined
onst x = {
 a: 1,
 b: function() {
   console.log(this);
 }
}
x.b() /// {a: 1, b: ƒ}
const z = x.b   // here this is window
z() // undefined

Leave a Reply

Your email address will not be published.