Arguments

An argument is an object created inside execution context of the function when it is invoked.

  • Created when the function is invoked.

  • arguments are the input parameters passed to the function.

  • It is an object that contains the index of the parameters as key and parameters are assigned as values against its index key.

  • arguments values are accessed with arguments key word.

  • arguments is not suggested to be used in the optimized codes instead use spread.

EX 1:
function greet() {
    console.log(arguments);
}
greet(); // {}

EX 2:
function greetME(name) {
    console.log(arguments);
}
greetME("Vijay"); // { 0: "Vijay" }

EX 3: // using spread to access arguments as array
function greetings(...args) {
    console.log(args);
}
greetings("Hello", "Vijay") // ["Hello", "Vijay"]

Last updated