0

what does a 'return' mean exactly in javascript?

please evaluate with an example. Thanks in advanced.

1st Dec 2016, 3:12 PM
Tarun Juluru
Tarun Juluru - avatar
3 ответов
+ 3
return in short is the variable that function will value and itself behave like the value. var a=5;. here a is 5; var b=a;. here b is 5; var c=sqr(a) here c is 25 as the function has code that returns a*a and it behaves like that
1st Dec 2016, 6:58 PM
Sandeep Chatterjee
0
Answers to your questions: Note: Any method declared void will not return a value. To use a 'return' statement, method must not be declared void and must contain a return statement with a corresponding return value e.g: return returnValue; Please look at the example below: class Symbad { public static void main(String[]args){ int sym = max(6,21); System.out.println(sym); } static int max (int a, int b){ if (a > b) {return a;} else {return b;} } } Explanation: int a = 6; int b = 21; If 'a' is greater than the value of 'b', then it will return 'a' and if 'a' is not greater than 21, it should return the value of 'b' that is why the else statement was used. I hope this helps.
1st Dec 2016, 4:58 PM
Olayinka Olajide
0
Answers to your questions: Note: Any method declared void will not return a value. To use a 'return' statement, method must not be declared void and must contain a return statement with a corresponding return value e.g: return returnValue; Please look at the example below: class Symbad { public static void main(String[]args){ int sym = max(6,21); System.out.println(sym); } static int max (int a, int b){ if (a > b) {return a;} else {return b;} } } // output is 21 Explanation: int a = 6; int b = 21; If 'a' is greater than the value of 'b', then it will return 'a' and if 'a' is not greater than 21, it should return the value of 'b' that is why the else statement was used. I hope this helps.
1st Dec 2016, 4:59 PM
Olayinka Olajide