ARGUMENT OBJECT IN JAVASCRIPT
Arguments is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. function getTotalSalary(HRA, basic, conveyance) { console.log(arguments[0]); // Expected Output: 1000 console.log(arguments[1]); // Expected Output: 7000 console.log(arguments[2]); // Expected Output: 2000 }); getTotalSalary(1000, 7000, 2000);
● The arguments object is not an Array. It has none of the Array properties except length. ● It can be converted to an array var args = Array.prototype.slice.call(arguments); OR // Using an array literal is shorter than above but allocates an empty array var args = [].slice.call(arguments); ● console.log(typeof arguments) // ‘object’ ;

Arguments Object in JavaScript

  • 1.
  • 2.
    Arguments is anArray-like object accessible inside functions that contains the values of the arguments passed to that function. function getTotalSalary(HRA, basic, conveyance) { console.log(arguments[0]); // Expected Output: 1000 console.log(arguments[1]); // Expected Output: 7000 console.log(arguments[2]); // Expected Output: 2000 }); getTotalSalary(1000, 7000, 2000);
  • 3.
    ● The argumentsobject is not an Array. It has none of the Array properties except length. ● It can be converted to an array var args = Array.prototype.slice.call(arguments); OR // Using an array literal is shorter than above but allocates an empty array var args = [].slice.call(arguments); ● console.log(typeof arguments) // ‘object’ ;