Skip to content

Instantly share code, notes, and snippets.

@nadar71
Created February 15, 2022 11:17
Show Gist options
  • Save nadar71/d7b04fdad66366986434e1103b6066d9 to your computer and use it in GitHub Desktop.
Save nadar71/d7b04fdad66366986434e1103b6066d9 to your computer and use it in GitHub Desktop.
Javascript callback samples, with parameters
<!DOCTYPE html>
<html>
<title>Web Page Design</title>
<head>
<script>
function calculate(num1, num2, callbackFunction) {
return callbackFunction(num1, num2);
}
function calcProduct(num1, num2) {
return num1 * num2;
}
function calcSum(num1, num2) {
return num1 + num2;
}
// alerts 75, the product of 5 and 15
alert(calculate(5, 15, calcProduct));
// alerts 20, the sum of 5 and 15
alert(calculate(5, 15, calcSum));
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment