function example() {
console.log(arguments);
console.log(arguments[0]);
} // Console outputs an array of each argument with its value
example('hi', 'hello');
// Outputs:
// ['hi', 'hello']
// 'hi'
what are the parameters and arguments in javascript
// 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);
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