/ Published in: JavaScript
Every function has an object called the arguments object. This is an object that contains all the arguments that were passed to the function. The example below shows how to access these. Very rarely used but useful to know. Note: it may look like an array, but it's better to think of it as an object with numbered properties.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function containerScope(){ var a = []; var b = {}; var c = true; var d = 22; function argumentsObject(a, b, c, d){ console.log(arguments.length); console.log(arguments[0]);//Array console.log(arguments[1]);//Object console.log(arguments[2]);//true console.log(arguments[3]);//22 arguments[3] = 55;//I have now changed d as well! console.log(arguments[3]); console.log(d); } argumentsObject(a, b, c, d); }