js/5/functioncalledcallback.html
2024-09-17 14:41:00 -05:00

19 lines
518 B
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

A function with no parameters that prints how many times its
been called. Hint: define a variable outside of the function to
keep track of the number of calls, like we did in the “Side
Effects” section on page 77.
<html><body><script>
let a = 0
let b = 0
let c = 0
function calledcallback (){a++;console.log(`calledcallback calls: ${a}`)}
callback = function () {b++;console.log(`callback calls: ${b}`)}
cb = () => {c++;console.log(`cb calls: ${c}`)}
calledcallback()
callback()
cb()
</script></body></html>