1

In Chrome on Windows, I have this in the console:

> Symbol.iterator
< Symbol(Symbol.iterator)
> Symbol.iterator = "Hello!";
< "Hello!"
> Symbol.iterator;
< Symbol(Symbol.iterator)

So Symbol.iterator (thankfully) doesn't change, but why doesn't my attempt to assign to it throw an error?

Green Grasso Holm
  • 468
  • 1
  • 4
  • 18

1 Answers1

2

In sloppy mode, the failed assignment doesn't cause an exception. Use strict mode instead:

(function(){ "use strict"; Symbol.iterator = "Hello" }())

Uncaught TypeError: Cannot assign to read only property iterator of function function Symbol() { [native code] }

Bergi
  • 630,263
  • 148
  • 957
  • 1,375