19 lines
518 B
HTML
19 lines
518 B
HTML
|
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()
|
|||
|
</script></body></html>
|