Arguments Object Function

Hello,

I am trying to execute the code, but the output itself showing NaN instead of the sum of numbers.

<script>
function addition(){
    var sum =0;
    for(i=0; i<=arguments.length; i++){
        sum += arguments[i];        
}
return sum;
}
alert(addition(1,2,3));
</script>
1 Like

Change this for(i=0; i<=arguments.length; i++){ to this for(i=0; i<arguments.length; i++){ and it will be fine!

1 Like

Yeah It’s working, Thank You PVgr.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.