0

JavaScript - Functions - Return - Help!

Hello, I'm not so certain about the return statement and I just noticed that when JavaScript reaches a return statement then the function stops executing the rest of the code. So my question is what happens if we want to calculate more than one variables in any given function. see below example: function myFunction(a, b, c, d) { var sum1 = a + b var sum2 = c + d return sum1 return sum2 } var result = myFunction(1, 1, 2, 2) console.log(result) I know the piece of code mentioned above might be wrong as i am so new to coding. Thanks in advance & Regards, Bahamin

14th Oct 2018, 1:32 PM
Bahamin Shahriari
Bahamin Shahriari - avatar
1 Answer
+ 2
You can return an array, for example: return [sum1, sum2];
14th Oct 2018, 1:38 PM
Roman Bive
Roman Bive - avatar