What is a function return?
The return statement stops the execution of the current function until returns a value from that called function.
Code:-
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<input type="button" value="Call Function" onclick="cal_fun();">
<div id="ans"></div>
<script>
function cal_fun()
{
var ret_val = ret_fun();
document.getElementById("ans").innerHTML = ret_val;
}
function ret_fun()
{
var a = 45;
var b = 34;
var c = a + b;
return c;
}
</script>
</body>
</html>
JavaScript:- function return
Reviewed by Network security
on
June 03, 2019
Rating:
No comments: