A Javascript function returns one and only one value.
|
|
I bet you already knew that not returning a value from a function, would return ‘undefined’.
Anywho.. you are in a pickle if you want to return multiple values. There is no return(sum, diff);
.
However, a lot of problems need multiple ‘things’ from the function output. What we do is to create an object in the function, populate it with multiple values and return the object to caller. The object packages all required variables.
|
|
Or, you could compress the whole function to ..
|
|