const circle = {
  radius: 20,
  diameter() {
    return this.radius * 2;
  },
  perimeter: () => 2 * Math.PI * this.radius,
};
console.log(circle.diameter());
console.log(circle.perimeter());

/*
The output is 
40
NaN
Here diameter() is a regular function whereas perimeter() is a arrow function.
In regular function the value of this depends on how the function is invoked.
If the function is invoked globally then this equals to global object i.e. window object.
If the function is invoked using an object then, this equals to the object which is invoking the function.
When it comes to arrow function unlike regular function, no matter how the arrow function is invoked this of arrow function always equals to the global object i.e. window object.
Here radius is declared inside the circle object so this of diameter() contains the radius value, hence the output will be computed with the radius value as 40.
But in case of perimeter() this equals to global object and it doesn't contains the value of radius.
So the radius value while computing the perimeter() will be NaN and hence the output will be NaN.
*/

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: