-
-
Save henryspivey/2383fffcbc02eb4f5fb23eb62fd5fbb7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Using `this` inside an object | |
// The object has functions created three different ways | |
// What will be the result of the three log statements? | |
const circle = { | |
radius: 10, | |
circumference: function () { | |
return (2 * Math.PI * this.radius); | |
}, | |
diameter() { | |
return (this.radius * 2); | |
}, | |
area: () => { | |
return (Math.PI * Math.PI * this.radius); | |
} | |
} | |
console.log(circle.area()); // NaN because arrow () uses lexical, in this case it's global, scope. | |
console.log(circle.diameter()); // 20 | |
console.log(circle.circumference()); //20π |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment