I cannot figure it out, why do some browsers allow the next code, and others do not:
'use strict';
(function() {
Number = 1;
toString = 1;
valueOf = 1;
})();
console.log(Number);
console.log(toString);
console.log(valueOf);
- Chrome 52 on Windows throws on toString and valueOf, but allows Number.
- Chrome 49 on Linux throws on valueOf, and allows others.
- Firefox 47 allows all.
- IE 11 allows Number.
- Opera allows Number.
At first, when I spotted this in Chrome, I thought, this is because of these "variables" had been already defined as properties of the global object. But window.hasOwnProperty('toString')
returns false, as well as for 'valueOf'. So I have no idea.
Could anyone explain this, please?
I'm asking because I need to test in unit tests, that global variables were not modified and this behavior makes it hard, because I do not know what behavior is the correct one so I could rely on it and not to find one day that it was fixed.