Created
February 15, 2022 11:17
-
-
Save nadar71/d7b04fdad66366986434e1103b6066d9 to your computer and use it in GitHub Desktop.
Javascript callback samples, with parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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