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

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

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 Denunciar

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 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