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.

Instagram โ— Twitter โ— Facebook

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!