MDN says that
A for...in loop only iterates over enumerable, non-Symbol properties.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
But I did a simple test and it shows that even Symbol properties are iterated in a "for...in" loop.
What is the catch here?
What am I missing?
Example 1:
var symbol = Symbol("test");
function Animal(name){
this.name = name;
}
Animal.prototype = {};
Animal.prototype.constructor = Animal;
function Dog(breed){
this.breed = breed;
this.name = "Dog";
this.s = symbol;
}
Dog.prototype = new Animal();
Dog.prototype.constructor = Dog;
console.log("001");
var d = new Dog("Sharo");
for (let x in d){
console.log(x, ":", d[x]);
}
console.log("002");
d = new Object();
for (let x in d){
console.log(x, ":", d[x]);
}
console.log("003");
d = new Number(5);
for (let x in d){
console.log(x, ":", d[x]);
}