function foo() {
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
foo(1,2,3);
//1
//2
//3
// what are the parameters and arguments in javascript
// Function parameters are the names listed in the function's definition.
// Function arguments are the real values passed to the function.
function calculateArea(width, height){ // width and height are Parameters
console.log*=(width * height);
}
calculateArea(2,3); // 2 and 3 are Arguments
// program to print the text
// declaring a function
function greet(name) {
console.log("Hello " + name + ":)");
}
// variable name can be different
let name = prompt("Enter a name: ");
// calling function
greet(name);
function name(param, param2, param3) {
}
function add() {
var sum = 0;
for (var i = 0, j = arguments.length; i < j; i++) {
sum += arguments[i];
}
return sum;
}
add(2, 3, 4, 5); // 14
function hello(name) {
alert("Hello " + name);
}
var name = "Person";
hello();
An Example of a function argument
function printValue(someValue) {
console.log('The item I was given is: ' + someValue);
}
printValue('abc'); // -> The item I was given is: abc