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

146
Visualizações
why does switch block not let the variable to be accessible after it?

i was trying to print the value of variable 'x' after switch block.However, i didnt put any expression to switch so it could escape the default case and print the value of x. But in line no 13,the x wont show any value in case there is a switch block in the code and it only worked when i removed the switch block.

let x = "0";

switch () { //switch with no expression 
case 0:
text = "Off";
break;
case 1:
text = "On";
break;
default:
text = "No value found";
}
document.getElementById("demo").innerHTML = x; //line no. 13
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

There is a syntax error. Your switch needs to have some expression. I mean switch(something here)

Because of the syntax error the script fails to execute further and hence you are not getting the output

about 4 years ago · Juan Pablo Isaza Relatório

0

The Switch does not accept empty expressions you should switch a variable or it will generate an error .. but if you want to you can use this one

let x = "0";

switch (true) { //switch with no expression 
case 0:
text = "Off";
break;
case 1:
text = "On";
break;
default:
text = "No value found";
}
document.getElementById("demo").innerHTML = x; //line no. 13
about 4 years ago · Juan Pablo Isaza Relatório
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