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

137
Vistas
Why does default case also run in a switch case fall though in javascript

Following is my javascript code:-

var time = 21
var text;
switch (time) {
  case 21:
    text = "1st case";
  case 22:
    text = "2nd case";
  case 23:
    text = "3rd case";
  default:
    text = "default";
}
console.log(text);

In the above code I wanted to know in line 9 and 11, why does this default statement also run and changes the text variable to "default"?

I wanted a little bit detailed explanation for this, according to my knowledge and a bit of gathering information I found that this will follow the rule of fall through, but I wanted to know why... or maybe there is another breakdown to this code.

NOTE - Removing break statement was intentional.

about 4 years ago · Juan Pablo Isaza
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