Created
May 3, 2022 09:01
-
-
Save omesser/899a5a82c6028348e2a1c26a4ed81a65 to your computer and use it in GitHub Desktop.
javascript - this
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
What will be the output of the following code? | |
*/ | |
function foo() { | |
console.log(this); | |
} | |
const obj = { | |
foo: function () { | |
console.log(this); | |
} | |
}; | |
class MyObject { | |
foo() { | |
console.log(this); | |
} | |
} | |
// 1 | |
foo(); | |
// 2 | |
obj.foo(); | |
// 3 | |
const myObj = new MyObject(); | |
myObj.foo(); | |
// 4 | |
const func = obj.foo; | |
func(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment