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

137
Vistas
Arrow function output in Javascript

I was reading about arrow function in js. There I found one question.

var arguments = [1, 2, 3];
var arr = () => arguments[2];
console.log(arr());

function foo(n) {
  var f = () => arguments[0] + n;
  return f();
}
console.log(foo(3));

It's output is showing 6. Can anyone explain why it is so?

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

0

arguments is the object for getting the arguments of the function called. Therefore arguments[0] is the argument n.

You need to change the name of the array such as arr = [1,2,3] and use it in the foo() function f = () => arr[0] + n;

var arr = [1, 2, 3];
var bar = () => arr[2];
console.log(bar());

function foo(n) {
  var f = () => arr[0] + n;
  return f();
}
console.log(foo(3));

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