FUNCTIONS
First, strict mode requires that named function arguments be unique. Consider the following:
// Duplicate named arguments
// Non-strict mode: No error, only second argument works
// Strict mode: Throws a SyntaxError
function sum (num, num){
// do something
}
In nonstrict mode, this function declaration doesn't throw an error. You'll be able to access the second num
argument only by name while the first is accessible only through arguments
.
The arguments
object also has a slight behavior change in strict mode. In nonstrict mode, changes to a named argument are also reflected in the arguments
object, whereas strict mode ensures that each are completely separate. For example:
// Change to named argument value
// Non-strict mode: Change is reflected in arguments
// Strict mode: Change is not reflected in arguments
function showValue(value){
value = "Foo";
alert(value); // "Foo"
alert(arguments[0]); // Non-strict mode: "Foo"
...