Basic JavaScript - Stand in Line

Tell us what’s happening:
Describe your issue in detail here.
Hi, my question is how is arr related to testArr? we are pushing to arr in the function but it pushes to testArr, i dont see how they are linked?

  **Your code so far**
function nextInLine(arr, item) {
// Only change code below this line
arr.push(item);
return arr.shift();
// Only change code above this line
}

// Setup
const 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));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Stand in Line

Link to the challenge:

Hello,

testArr is just an array that is being created outside the function for the purpose of testing the function.

It is passed in as input to the function.

Inside the function, the input array is referred to as arr.

Does this answer you?

If the above answer does not clarify your doubts, when we called a function with parameters we are to assign arguments to the function so that those arguments will assign as the parameters of the function when we called it.
Here function,

nextInLine(arr, item)

has two parameters which are arr and item. When we called the function with arguments testArr and 6 the values of the arguments will be assigned to the parameters inside the function. So, now inside the function

arr=testArr , item=6 

Hope I answer your question :grinning:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.