return expression;
return
x + y;
return;
x + y;
return (
x + y;
);
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p> Welcome to the bianchenghao6.com </p>
<p> Example of the JavaScript's return statement </p>
<script>
var res = fun(12, 30);
function fun(x, y)
{
return x * y;
}
document.write(res);
</script>
</body>
</html>
Welcome to the bianchenghao6.com
Example of the JavaScript's return statement
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p> Welcome to the bianchenghao6.com </p>
<p> Example of the JavaScript's return statement </p>
<script>
var x = fun();
function fun() {
var i = 1;
while(i) {
document.write(i + '<br>');
if (i == 4) {
return;
}
document.write(i + '<br>');
i++;
}
document.write('Hello world');
}
</script>
</body>
</html>
Welcome to the bianchenghao6.com
Example of the JavaScript's return statement
<!DOCTYPE html>
<html>
<head>
<title> JavaScript return </title>
</head>
<body>
<p> Welcome to the bianchenghao6.com </p>
<p> This is an example of returning multiple values using array </p>
<script>
function getData() {
let fname = 'John',
lname = 'Rickman',
age = '25',
occupation = 'Private Employee';
return [fname, lname, age, occupation];
}
const [fname, lname, age, occupation] = getData();
document.write("Name = " + fname + " " + lname + "<br>");
document.write("Age = " + age + "<br>");
document.write("Occupation = " + occupation);
</script>
</body>
</html>
Welcome to the bianchenghao6.com
This is an example of returning multiple values using array
<!DOCTYPE html>
<html>
<head>
<title> JavaScript return </title>
</head>
<body>
<p> Welcome to the bianchenghao6.com </p>
<p> This is an example of returning multiple values using object </p>
<script>
function getData() {
let fname = 'John',
lname = 'Rickman',
age = '25',
occupation = 'Private Employee';
return {
fname,
lname,
age,
occupation
};
}
let {fname, lname, age, occupation} = getData();
document.write("Name = " + fname + " " + lname + "<br>");
document.write("Age = " + age + "<br>");
document.write("Occupation = " + occupation);
</script>
</body>
</html>
Welcome to the bianchenghao6.com
This is an example of returning multiple values using object