What is the purpose of return value using return funtion pls explain?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the purpose of return value using return funtion pls explain?!

Return function

7th Jul 2020, 1:21 PM
Prasanth Kumar
Prasanth Kumar - avatar
1 Answer
+ 2
For example, consider this function in JavaScript. function triple(num) { var triple_val = num * 3; } console.log(triple(4)); //Outputs undefined Why? Because triple_val was not returned. Change it to this function triple(num) { var triple_val = num * 3; return triple_val; } console.log(triple(4)); //Outputs 12 Hope you understand. The return keyword indicates that a value should be returned when the function is called.
7th Jul 2020, 6:09 PM
Ore
Ore - avatar