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

140
Vistas
How to access the value of invoked function in switch statemant

Consider the following code:

switch (doSomething()) {
    case "1":
        return 1;
    case "2":
        return 2;
    default:
        console.log(RETURNED_VALUE); // I want here to access the value returned from doSomething
}

I want to print the value returned from doSomething, without storing it first in a variable. Is it possible? (something similar to this)
Thank you

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Good night!

Switch is a conditional structure, like if or ternary operator. It's only a set of instructions, not a object allocated in memory. Because of this, you can't have a "this" feature inside of it. However, if you don't want to store the variable for long time, you can just wrap the switch inside a function, like that:

function switchDebug () {
    let value = doSomething(); 
    switch (value) {
        case "1":
            return 1;
        case "2":
            return 2;
        default:
            console.log(value);
    }
}

This way, the variable will be cleaned after use of function, because it will be a local scope variable of the function.

over 4 years ago · Santiago Trujillo 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