0

Can a function return two values. for eg. return var1; return var2

31st Dec 2017, 7:04 AM
Arvind Tarpasa
Arvind Tarpasa - avatar
2 Réponses
+ 13
if they are separated by some logic, sure. but once a return statement is encountered the function ends
31st Dec 2017, 7:06 AM
jay
jay - avatar
+ 9
If you need to return multiple values, you could use an object with properties for those values. Example: return { var1: someValue, var2: anotherValue };
31st Dec 2017, 7:11 AM
David Carroll
David Carroll - avatar