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

135
Views
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 answers
Answer question

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 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!