Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Last active May 12, 2020 06:32
Show Gist options
  • Save prof3ssorSt3v3/14107ed915d09ccd77c8b2a8012a265b to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/14107ed915d09ccd77c8b2a8012a265b to your computer and use it in GitHub Desktop.
// 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()); //
console.log(circle.diameter()); //
console.log(circle.circumference()); //
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment