+ 1
Can someone please explain me return statement in javascript or java
function myFunction(a, b) { var x = a * b; } myFunction(5, 6); document.write(x); This code is same as function myFunction(a, b) { return a * b; } var x = myFunction(5, 6); document.write(x); Please tell and vote;
5 Answers
+ 4
Vihaan Sejwani There's a difference between JavaScript and Java. After looking at the syntax I suppose you're asking about JavaScript. Basically "return" returns the output to browser's console while "document.write" rewrites the HTML document to return something.
+ 2
Txn ekansh by the way I was talking about both java and javascript but I gave example of JavaScript
+ 1
return statement in a function is like tellx the function that when i call you,after your duty just return me smethx.return could send a character,int,array e.t.c.
+ 1
But why use return when it can be done other way round
0
vihaan wat other way are you suggesting?