why there should be two variables in the parentese of functions?
what are their roles?
example code below:
function nextInLine(arr, item) {
// Only change code below this line
return item;
// Only change code above this line
}
// Setup
var testArr = [1,2,3,4,5];
// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
Just for clarification here, A parameter is basically a variable that the function takes, so in the background, it creates a local variable for the function itself. It will use the value that was given to the function. For example:
function helloWorld(sentence1, sentence2) {
return sentence1 + sentence2;
};
console.log(helloWorld("hello", "world")); //this will output helloworld.
You can name your parameter with any name, but always try to name it with something explanatory, that you can always understand what the parameter is holding, that’s why arr is holding an array. Learn more about parameters here: https://www.w3schools.com/js/js_function_parameters.asp