circle is not iterable

function Circle (radius) {
this.radius = radius;
this.draw = function () {
console.log(‘draw’);
}
}
const circle = new Circle (2);
console.log(circle);

const another2 = [ …circle ];

console.log(another2);

error 2_Objects.js:53 Uncaught TypeError: circle is not iterable

The issue is this line:

const another2 = [ …circle ];

This syntax is used to spread an iterable (like an array) into another array but circle is an object, To create a copy of the object, you should use the spread syntax for objects, like this:

function Circle(radius) {
    this.radius = radius;
    this.draw = function () {
        console.log('draw');
    };
}

const circle = new Circle(2);
console.log(circle);

const anotherCircle = { ...circle };
console.log(anotherCircle);
1 Like

Thank you. Yes later founded the bug