Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
what is the use case for static inside class in javascript

I am a beginner in Javascript and I didn't understand the concept of static variables or methods inside Class. I don't understand why and when we need them and what is the use case for them? for example this class

class Car {
  constructor(name) {
    this.name = name;
  }
  static hello() {
    return "Hello!!";
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

OOP (including classes) was recently added to JavaScript, and in my opinion, it's more like syntactic sugar that allows us to structure our data more easily, or perhaps just for the satisfaction of using the new keyword. These OOP features were adapted from other languages, such as Java.

Static methods allow other pieces of your code to access variables and methods from a class without creating an instance of it (not using the new keyword).

This is especially helpful when you want to retrieve data from a class without creating an instance or initializing the constructor.

Take, for example, a real world example of Web Components:

class WhyStatic {
  /* other methods... */
  static get observedAttributes() {
    return ["name", "why", "test"];
  }
}

This allows the custom elements function to access the observed attributes of an HTML element without creating an extra instance.

In other words, we can create non-instance specifc data for a class that gets accessed outside, and only outside, a class instance.

That's why we need static in OOP.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!