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

206
Views
¿JS pasa el parámetro predeterminado como una variable que se define dentro de esa función?

Por ejemplo:

 function mf(z, xc, lol = b) { // I need lol = azazaz let b = azazaz ... }

En lugar de lol = azazaz , obviamente obtengo b is not defined .

Que puedo hacer:

 function mf(z, x, c, lol = "b") { //parameter lol is a string let b = azazaz lol = eval(lol) //now lol = azazaz ... }

También puedo hacer esto:

 function mf(z, x, c, lol) { //parameter lol doesn't have default value b = azazaz if (lol == 0) { lol = b //default value of lol = azazaz } ... }

Pero el primero parece tan poco profesional, el segundo tiene una declaración if adicional que tampoco quiero. ¿Hay alguna manera mejor de hacer esto?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si definir la variable dentro de la función no es un requisito difícil, probablemente pueda aprovechar los cierres para hacer algo como:

 const b = 'azazaz'; function mf(z, x, c, lol = b) { ... }

O tal vez use 'OR' para evitar if

 function mf(z, x, c, lol) { //parameter lol doesn't have default value let b = 'azazaz'; lol = lol || b; ... }
about 4 years ago · Juan Pablo Isaza Report

0

Si necesita cambiar el parámetro y reutilizarlo, debe volver a llamar a la función como:

 //every time function change lol and recall function function mf(z, x, c, lol) { console.log('lol now is: ' + lol); lol++; if (lol <= 10) { mf(1, 2, 3, lol); } } mf(1, 2, 3, 0);

about 4 years ago · Juan Pablo Isaza 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!