One reason why push
may be confusing is because it returns the new length of the array:
The push() method extends an array by adding new items to the end, and then shows the updated length.
Although the push function is actually being executed, the return value might not match your expectations.
Interestingly, JavaScript was created in just 10 days, which explains some of its quirks. Despite initial limitations, JavaScript still offers some functional programming capabilities (originally requested by marketing for a "Java-like" language).
While JavaScript supports functional programming, there are certain obstacles that programmers may encounter.
This quote sheds light on the situation:
Luckily Eich managed to incorporate innovative ideas into the language despite constraints.
The debate continues about whether push
should deliver the array's length, the pushed element, or the entire array itself as a return value.