DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

Add Properties to functions

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.

InstagramTwitterFacebook

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

codedrops.tech

Top comments (3)

Collapse
 
atharv774448847 profile image
sumanta.Sharma@hotmail.Com

Yfutf

Collapse
 
atharv774448847 profile image
sumanta.Sharma@hotmail.Com

Tory
Reach leave
Ropd

Collapse
 
futureistaken profile image
R Z

It's called static properties!