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

325
Views
Showing Error "argument is not defined" while adding multiple arguments in arrow function but It's Working in Normal Function call

//Example - 1

function add1(){

    if (arguments.length == 0){

        document.write("NO Argument Passed!");
    }
    else{

        let sum = 0;

        for(let num in arguments){

            sum += arguments[num];
        }

        document.write(sum);
    }
}

add1(5,10); 

In this example, I am getting the correct result.

//Example - 2 ( With Arrow Function)

let sum = () => {

    if( arguments.length == 0){

        document.write("NO Argument Passed!");
    }
    else{

        let sum1 = 0;

        for(let number in arguments){

            sum1 += arguments[number];
        }

        document.write(sum1);
    }


};

sum(10,20);

*Here I am getting an error in console "arguments is not defined". Please tell me where I did Wrong.Thank you..!

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

0

This is because arrow functions do not have argument bindings.

option 1 changing arrow function to take an array arguments parameter

let sum = (arguments) => {
    if( arguments.length == 0){
        console.log("NO Argument Passed!");
    }
    else{

        let sum1 = 0;

        for(let number in arguments){

            sum1 += arguments[number];
        }

        console.log(sum1);
    }
};
sum([10,20]);

option 2 rest parameters which allows indefinite amount of arguments

let sum = (...arguments) => {
    if( arguments.length == 0){

        console.log("NO Argument Passed!");
    }
    else{

        let sum1 = 0;

        for(let number in arguments){

            sum1 += arguments[number];
        }

        console.log(sum1);
    }
};
sum(10,20);

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!