DEV Community

Fulton Browne
Fulton Browne

Posted on

What is the equivalent of a static variable in JS

I am starting to get my feet wet with js, I am wondering is there an equivalent to Java static variable in node js.

Top comments (5)

Collapse
 
deciduously profile image
Ben Lovy • Edited

Doesn't Node support the ES6 class syntax? I think you can just do exactly what you want.

Collapse
 
fultonbrowne profile image
Fulton Browne

wow didn't know it was that easy, thanks!

Collapse
 
deciduously profile image
Ben Lovy

Classes in ES6+ are really just syntax sugar, so I don't think this actually answers your question in quite the right spirit, but it is a feature you can use :)

Thread Thread
 
raghavmisra profile image
Raghav Misra

I 100% agree with you Ben, but if a feature is there, might as well use it, right?

Thread Thread
 
ionline247 profile image
Matthew Bramer

with and eval are features too. You might be better off looking into how functional programming can solve the problem you're solutioneering.