Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Cómo acceder al valor de la función invocada en switch statemant

Considere el siguiente código:

 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 }

Quiero imprimir el valor devuelto por hacerAlgo, sin almacenarlo primero en una variable. ¿Es posible? (algo parecido a this )
Gracias

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

¡Buenas noches!

Switch es una estructura condicional, como si o un operador ternario. Es solo un conjunto de instrucciones, no un objeto asignado en la memoria. Debido a esto, no puede tener una función "esto" dentro de él. Sin embargo, si no desea almacenar la variable durante mucho tiempo, puede envolver el interruptor dentro de una función, así:

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

De esta manera, la variable se limpiará después del uso de la función, porque será una variable de ámbito local de la función.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!