Creating functions in JavaScript - Part 2
Chinwendu Agbaetuo
Posted on April 12, 2024
Create a function with no parameters that prints how many times it’s been called.
let printCallTimes = 0;
const randomFunc = () => {
printCallTimes++;
console.log(printCallTimes)
return printCallTimes;
}
randomFunc();
randomFunc();
randomFunc();
console.log(`The function has been called ${printCallTimes} times`);
> 1
> 2
> 3
> "The function has been called 3 times"
💖 💪 🙅 🚩
Chinwendu Agbaetuo
Posted on April 12, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.