Answers for "arguments object in javascript"

2

javascirpt arguments object

// With Rest Parameter
let sum = (...nums) => {
  let total = 0;
  for (let num of nums) {
    total += num;
  }
  return total;
};
console.log(sum(4, 23, 65, 2)); // 94


// Before
function sum() {
  let total = 0;
  for (let argument of arguments) {
    total += argument;
  }
  return total;
}
console.log(sum(4, 23, 65, 2)); // 94
Posted by: Guest on September-28-2021
27

variable arguments js

function foo() {
  for (var i = 0; i < arguments.length; i++) {
    console.log(arguments[i]);
  }
}

foo(1,2,3);
//1
//2
//3
Posted by: Guest on July-09-2020
2

arguments object in javascript

var sum = 0;
function addAll(){
    for (var i = 0; i<arguments.length; i++){
        sum+=arguments[i];
    }
    console.log(sum);
}

addAll(1, 2, 3, 4, 5, 6, 7, 8, 9,10); //we can provide inifite numbers as argument
Posted by: Guest on December-19-2020
1

js array as parameter

function myFunction(a, b, c) {//number of parameters should match number of items in your array
  	//simple use example
  	console.log("a: " + a);
  	console.log("b: " + b);
  	console.log("c: " + c);
}

var myArray = [1, -3, "Hello"];//define your array
myFunction.apply(this, myArray);//call function
Posted by: Guest on April-02-2020
0

arguments object in javascript

function test(a, b, c){
    // console.log(arguments);
    // console.log(JSON.stringify(arguments));
    // console.log(typeof a);

    // var sum = 0;
    // for (var i = 0; i<arguments.length; i++){
    //     sum += arguments[i];
    // }
    // console.log(sum);

    //for (var i = 0; i<arguments.length; i++){
    //    console.log(arguments[i]);
    //}
  
    console.log(arguments[0]);
}

test(10, 20, 30);
Posted by: Guest on December-19-2020

Code answers related to "arguments object in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language