Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda