+ 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;

2nd Apr 2018, 11:19 AM
Vihaan Sejwani
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.
2nd Apr 2018, 11:38 AM
Ekansh
+ 2
Txn ekansh by the way I was talking about both java and javascript but I gave example of JavaScript
4th Apr 2018, 4:23 PM
Vihaan Sejwani
+ 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.
4th Apr 2018, 11:06 PM
Bate Martin
Bate Martin - avatar
+ 1
But why use return when it can be done other way round
5th Apr 2018, 6:23 AM
Vihaan Sejwani
0
vihaan wat other way are you suggesting?
5th Apr 2018, 10:34 PM
Bate Martin
Bate Martin - avatar