Javascript overloads & overrides without prior notice/indication/need

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]

The return value of push is not the new array. The return value is the length of the new array. This has nothing to do with overloading or overriding.

1 Like