Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda