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

249
Vistas
How to convert an anonymous function with multiple arguments into an arrow function?

I am able to assign the value of an anonymous function to a variable like this:

let x = function(y,z) { return y + z }(1,2);

The resulting value of x is 3. Following the guide at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions the equivalent using arrow functions should be this I think.

let x = (y = 1, z = 2) => { return y + z };

However the value of x in this case becomes NaN. Why is that?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

let x = (y = 1, z = 2) => { return y + z } assigns the function to the variable, not its call. To assign the function call to a variable first you need to call it. So, arrow function equivalent of let y = function(y,z) { return y + z }(1,2); would be:

let x = ((y = 1, z = 2) => { return y + z })()
// or
let x2 = ((y, z) => { return y + z })(1,2)
// or
let x3 = ((y = 1, z = 2) => (y + z))()
// or
let x4 = ((y, z) => (y + z))(1,2)

let y = function(y,z) { return y + z }(1,2);

console.log(x)
console.log(x2)
console.log(x3)
console.log(x4)
console.log(y)
.as-console-wrapper { max-height: 100% !important; top: 0; }

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