2024-10-03 11:29:13 -05:00
|
|
|
|
A function with no parameters that prints how many times it’s
|
|
|
|
|
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()
|
2024-09-17 14:41:00 -05:00
|
|
|
|
</script></body></html>
|