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

324
Vistas
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 Respuestas
Responde la pregunta

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