Arguments Keyword in JavaScript | The Complete JavaScript Course | Ep.45

preview_player
Показать описание

Have any doubts? Join this Telegram group and ask your question. You can also share the projects that you make in this group.

00:01 The 'arguments' keyword in JavaScript is automatically created within every function.
01:13 Understanding arguments and passing them in JavaScript functions
02:30 Passing and accessing arguments in JavaScript
03:47 Creating a function with variable number of arguments for adding them
06:09 Understanding the 'arguments' keyword in JavaScript
07:52 Removing function declaration and using arrow functions in JavaScript
09:30 Converting arguments to arrays in JavaScript
11:19 Understand the arguments keyword in JavaScript for old codebases

Social Media

Music by geoffharvey from Pixabay
Рекомендации по теме
Комментарии
Автор

function add() {
let array = Array.from(arguments);
let sum = 0;
for (var i = 0; i < array.length; i++) {
sum += array[i];
}
return sum;
}
add(2, 3, 4, 5, 6, 7)
27

s.siddiqui
Автор

5:54 =>>>>
function add() {
let sum = 0
for(let i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
}

add(1, 3, 1, 23) // returns 28

manvvar_hasan
Автор

very well explained. Answer of the homework question is => const argumentsArray = Array.from(arguments);
console.log(argumentsArray);
//now after converting it to the array let us again calculate the sum of the arguments by using reduce method
const sumByReduceMethod = argumentsArray.reduce(
(accumulator, current, index) => {
return accumulator + current;
// console.log(accumulator);
},
0
);

Thank you once again for this amazing lecture
💚

KeshavSharma-uogi
Автор

10:40
// method 1 using Array.from(arguments)
// function sum() {
// let sum = 0;
// const args = Array.from(arguments);
// for (let num of args) {
// sum += num;
// }
// return sum;
// }

// method 2 using spread opeartor

function sum() {
let sum = 0;
let convert = [...arguments];
for (let nums of convert) {
sum += nums;
}
return sum;
}

kapilrana
Автор

adding the arguments by converting the arguments into array and then reduce method:

function add () {
const args = Array.from(arguments)
const sum = args.reduce((acc, curr) => {
return acc + curr
}, 0)
return sum
}

adityakarki
Автор

function add() {
return Array.from(arguments).reduce((acc, ele) => {
return acc + ele;
});
}
console.log(add(4, 3, 3)); // output - 10

NirbhayMarde-qzkj
Автор

4:00
function add() {
let sum = 0;
for(let i = 0; i<arguments.length;i++) {
console.log(arguments[i]);
sum = sum + arguments[i];
}
return sum;
};

adityasinghh
Автор

function sum() {
let sum = 0;
let convert = [...arguments];
for (let nums of convert) {
sum += nums;
}
return sum;
}
I started this playlist This is day 5 I know basics of javascript so I will binge watch basic part and if I found any topic which I don't know then I will try that topic

Pushpak_UE_devlover
Автор

// converting the arguments of a function into an array

let arr = []
function add(a, b) {
console.log(arguments)
for (let i = 0; i < arguments.length; i++) {
console.log(arguments[i])
arr.push(arguments[i])
}
// console.log('result =', a + b)
return a+b
}

add(5, 6, 7, 2)
console.log(arr)

// adding the numbers in the array using reduce array method
const sum = arr.reduce(function (accumulator, currentValue){
return accumulator + currentValue
}, 0)
console.log(sum)

manasbhattacherjee
Автор

function add(){
var args =[];
for(let i= 0; i< arguments.length ; i++){
args[i] = arguments[i];
}
return args.reduce((acc, cur)=>{
return acc + cur;

}, 0)
}

console.log(add(1, 2, 3, 4));

Asadalicoder
Автор

we can convert arguments to an array by one of the following methods
slice()
Array.from()
spread operator i.e. [...arguments]
for example
const args =Array.from(arguments);
and then we can add the elements of this array using reduce as
console.log(args.reduce((acc, current)=>acc+current))

smrititripathi
Автор

function add(){
console.log(arguments);
let sum=0;
let i=0;
while(typeof arguments[i]== "number"){
sum+=arguments[i]
i++;
}
console.log("sum is", sum)
}

abdullahkhan-ezpi
Автор

aap sbse alag or accha padhate h paid course k alava main aapka sara vedio dekhti hu and kl maine some and every methods apka sikhne k baad X pr post kiya logo n like kiya and sbhi ko bahut accha laga thnk you sir itna accha padhane k liye.

KrishJaiswal-frgn
Автор

Day 22: video 45 completed ....thank you sir making such great Video 😊....
22 video left for first project... excitement is on the peak 🎉🎉

Collecting_one_piece_fan
Автор

Assignment :

function add() {

const convertedArray = Array.from(arguments); // converting Array like object into Array
convertedArray.reduce((acc, curValue) => {
return acc + curValue;
}, 0);
}
add(1, 2, 3, 4, 5);

RamayanKiChaupaiyaan
Автор

11:00 =>>>
function example() {
const argsArray = [...arguments];
const sum = argsArray.reduce((acc, current) => acc + current, 0);
console.log(sum);
}
example(1, 2, 3); // 6

manvvar_hasan
Автор

#Solution
function add2() {
let array = [];
for(let i = 0; i < arguments.length; i++) {
array[i] = arguments[i];
}
return array.reduce((accumulator, element) => {
return accumulator + element;
})
}

sketchoholic
Автор

11:00
function sum() {
let convert = [...arguments];
const sum = convert.reduce((acc, currVal) => {
return acc + currVal;
}, 0);
return sum;
}

kapilrana
Автор

Completed lecture 45🎉🎉
Thankyou bhaiya for the js course
This is best js course on whole yt plateform
Phli baar js se drr nhi lg rha 😅

manishasaini
Автор

function Add(){
let arr = [...arguments]
const sum = arr.reduce((acc, curr) => {
return acc+curr
}, 0)
return sum
}
console.log(Add(5, 5, 5, 5, 5))

pondacherry
join shbcf.ru