gaurav bhardwaj
-
Posts
2 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by gaurav bhardwaj
-
-
if i take this example
function add_num(){
var num1=10;
var num2=10;
var num3=num1+num2;
document.write(num3);
}
add_num();
and
function add_num(){
var num1=10;
var num2=10;
var num3=num1+num2;
return num3;
}
var total_num=add_num();
document.write(total_num);
Q.1-:Why do we use return statement ,
Q.2-:When we get the same answer by example no .1 so why do we use return statement.
Q.3-:If I change the return statement like ;(return 50;) and call the function ,I got the 50 .rather then it should be 20. why.
Return Statement
in JavaScript
Posted · Edited by gaurav bhardwaj
Thank you for reply,But i do not understand the concept.Yes this is right return statement use to get a value return from function ,But Where should I use that ,because i am getting same answer by example first,And if i fix the value in return statement so I will get the that value rather It does matter how the function design or write