Tell us what’s happening:
I was trying to solve a challenge and when i was testing my solution i found out that the following codes provide different results although in other languages (Java,C++, Python) they are consistent (i.e. adamant results)
Code 1:
var temp = [n];
temp.push(n-1);
return temp; // temp= [n,n-1]
Code 2:
return [n].push(n-1); //returns 2 although it should return [n, n-1]
Code 3:
var temp = [n];
return temp.push(n-1); //returns 2 although it should return [n, n-1]