loading...

Add Properties to functions

318097 profile image Mehul Lakhanpal Originally published at codedrops.tech ・1 min read
function greetings() {
  console.log("hello world");
  greetings.counter++;
}
greetings.counter = 0;

greetings();
greetings();

console.log(`Called ${greetings.counter} times`); // Called 2 times
Enter fullscreen mode Exit fullscreen mode

Thanks for reading πŸ’™

Follow @codedrops.tech for daily posts.

Instagram ● Twitter ● Facebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Discussion

pic
Editor guide
Collapse
atharv774448847 profile image
Collapse
atharv774448847 profile image
sumanta.Sharma@hotmail.Com

Tory
Reach leave
Ropd

Collapse
futureistaken profile image
R Z

It's called static properties!