Can I return a push() directly?

Tell us what’s happening:
May I know why the second scenario doesn’t yield the same output as the first scenario? Why is it necessary to execute separate lines for the push to be returned? And also why would the second scenario yield an output of 3?

   **Your code so far**

function test(param1, param2) {
  return param1
console.log(test(["cat", "dog"],'duck'))       //display [ 'cat', 'dog', 'duck' ]

function test2(param3, param4) {
  return param3.push(param4);
console.log(test2(["cat", "dog"],'duck'))      //display 3
   **Your browser information:**

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

push method returns the new length of the array.


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