Can anyone explain why this IIFE passed in argument mutates in-scope variable the way it does to undefined?

Viewed 39

Any other cases not involving undefined that would cause this mutation? I'm having a hard time wrapping my head around this example:

(function(undefined){
var str = 'foo';
console.log(str === undefined); // true
})('foo');

1 Answers

undefined is a variable that you can reassign outside of strict mode, although strict mode aparently doesn't protect you from naming arguments that way.

console.log(typeof undefined);
(function(undefined){
var str = 'foo';
console.log(str === undefined); // true
console.log(typeof undefined);
})('foo');

Related