Function Parameters

Example

<!DOCTYPE html>
<html>
<body>

<p>Setting a default value to a function parameter.</p>
<p id=”demo”></p>

<script>
function myFunction(x, y) {
if (y === undefined) {
y = 0;
}
return x * y;
}
document.getElementById(“demo”).innerHTML = myFunction(4);
</script>

</body>
</html>

Output

Setting a default value to a function parameter.

Updated: February 13, 2019 — 5:53 am
Java Script © 2019