Behaviour of a functions arguments list

suggest change

arguments object behave different in strict and non strict mode. In non-strict mode, the argument object will reflect the changes in the value of the parameters which are present, however in strict mode any changes to the value of the parameter will not be reflected in the argument object.

function add(a, b){
    console.log(arguments[0], arguments[1]); // Prints : 1,2

    a = 5, b = 10;

    console.log(arguments[0], arguments[1]); // Prints : 5,10
}

add(1, 2);

For the above code, the arguments object is changed when we change the value of the parameters. However, for strict mode, the same will not be reflected.

function add(a, b) {
    'use strict';

    console.log(arguments[0], arguments[1]); // Prints : 1,2

    a = 5, b = 10;

    console.log(arguments[0], arguments[1]); // Prints : 1,2
}

It’s worth noting that, if any one of the parameters is undefined, and we try to change the value of the parameter in both strict-mode or non-strict mode the arguments object remains unchanged.

Strict mode

function add(a, b) {
    'use strict';

    console.log(arguments[0], arguments[1]); // undefined,undefined 
                                             // 1,undefined
    a = 5, b = 10;

    console.log(arguments[0], arguments[1]); // undefined,undefined
                                             // 1, undefined
}
add();
// undefined,undefined 
// undefined,undefined

add(1)
// 1, undefined
// 1, undefined

Non-Strict Mode

function add(a,b) {

    console.log(arguments[0],arguments[1]);

    a = 5, b = 10;

    console.log(arguments[0],arguments[1]);
}
add();
// undefined,undefined 
// undefined,undefined

add(1);
// 1, undefined
// 5, undefined

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Strict mode:
* Syntax
* Behaviour of a functions arguments list

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
39 Strict mode
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde