JavaScript arguments object

preview_player
Показать описание
Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

The JavaScript arguments object is a local variable available within all functions. It contains all the function parameters that are passed to the function and can be indexed like an array. The length property of the arguments object returns the number of arguments passed to the function.

JavaScript arguments object example :
function printArguments()
{
{
}
}

printArguments();
printArguments("A", "B");
printArguments(10, 20, 30);

Is it possible to pass variable number of arguments to a JavaScript function
Yes, you can pass as many arguments as you want to any javascript function. All the parameters will be stored in the arguments object.

function addNumbers()
{
var sum = 0;
{
sum = sum + arguments[i];
}
}

addNumbers();
addNumbers(10, 20, 30);

The arguments object is available only inside a function body. Attempting to access the arguments object outside a function results in 'arguments' is undefined error. Though you can index the arguments object like an array, it is not an array. It does not have any Array properties except length. For example it does not have the sort() method, that the array object has. However, you can convert the arguments object to an array.

Converting JavaScript arguments object to an array
function numbers()
{
}

numbers(50, 20, 40);

Output : 20, 40, 50

Converting JavaScript arguments object to an array using array literals
function numbers()
{
}

numbers(50, 20, 40);

Output : 20, 40, 50
Рекомендации по теме
Комментарии
Автор

previous video, you have mentioned with sort(), for integers we need to call function (a-b) for ascending and (b-a) for descending.how you got elements sorted in this video without that functionality.can you please explain

machireddysaivenkatamanojk
Автор

I really like you calming voice, very very clear explanation, my tons of respects to you!

girlandhercomputer
Автор

FINALLY! FINALLY I got the concept of closures! Thank you!!

RudigerKeler
Автор

thanks for dumbing it down for people like me :)

jarlorm
Автор

Cool point about how the argument object is only available inside the body of a function.

McGavel
Автор

Sir to this sort method if we pass values 100, 20, 10
we get wrong output as 10, 100, 20
instead of 10, 20, 100

anishbapat
Автор

That was a cool trick using the Array Literal.

McGavel
Автор

1.How "Arguments" will work in closures....??
2.How did the sort() function work for integers

HemanthHemu
Автор

why slice.call? slice makes a copy of the original array, while call changes the context of the this keyword

KLNNNN
Автор

Sir Please Tell Us, How We Can Intregrate The Payment Gateways In Asp Website 

VivekG
Автор

These Videos are not playing..., at all:
JavaScript arguments object
JavaScript Cookies
JavaScript strings and regular expressions
JavaScript substring example
Set and get multiple cookies in JavaScript

XTimNet