arguments in function javascript code example
Example 1: javascript function variable arguments
function foo() {
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
foo(1,2,3);
Example 2: how to access any argument in javascript
function example() {
console.log(arguments);
console.log(arguments[0]);
}
example('hi', 'hello');
Example 3: parameters in javascript
function myFunction(x, y) {
if (y === undefined) {
y = 2;
}
}
Example 4: how to create a function with parameters in JavaScript
function name(param, param2, param3) {
}