TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Arguments in JavaScript
Kaushik S
Nov 23
2015
Code
958
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Example 1:
Simple function without arguments.
Example 2:
A function with 1 parameter and how to access using argument.
Example 3:
A function with 2 parameter and how to access using argument.
Example 4:
A function with 2 parameter and to find the number of parameters.
Example 5:
To access parameters with for loop.
Example 6:
Displays the contents and the output of the function.
Example 7:
To know the type of document.
<html>
<head >
<title></title>
</head>
<body>
<form id=
"form1"
>
<div>
</div>
</form>
<script type=
"text/javascript"
>
function
Example1(arg)
{
document.write(
"Example1 :"
+ arg);
}
Example1(
"Sachin Tendulkar"
)
function
Example2(arg) {
document.write(
" Example2 :"
+ Example2.arguments[0]);
}
Example2(
"Sachin Tendulkar "
)
function
Example3(arg1,arg2) {
document.write(
" Example3 :"
+ Example3.arguments[0] +
" and "
+ Example3.arguments[1]+
" are great"
);
}
Example3(
"Sachin Tendulkar"
,
"Saurav Ganguly"
);
function
Example4(arg1, arg2) {
document.write(
"Length:"
+arguments.length);
}
Example4(
"Sachin Tendulkar"
,
"Saurav Ganguly"
)
function
Example5() {
document.write(
"Length:"
+ arguments.length);
}
Example5(
"Sachin Tendulkar"
,
"Saurav Ganguly"
)
function
Example6() {
for
(
var
i = 0; i < arguments.length;i++) {
document.write(arguments[i]+
" "
);
}
}
Example6(
"Sachin Tendulkar"
,
"Saurav Ganguly"
)
function
Example7() {
document.write(
":"
+ arguments[0]);
document.write(
":"
+ arguments[1]);
}
Example7(
"Sachin Tendulkar"
,
"Saurav Ganguly"
);
function
Example8() {
arguments[0]=
"Kaushik"
;
document.write(
":"
+ arguments[0]);
document.write(
":"
+ arguments[1]);
}
Example8(
"Sachin Tendulkar"
,
"Saurav Ganguly"
);
function
Example9()
{
var
sum = 0;
for
(
var
i = 0; i < 5; i++) {
sum = sum + i;
}
document.write(
"output: "
+sum+
" :"
);
document.write(arguments.callee);
}
Example9();
function
Example10() {
document.write(
typeof
arguments)
}
Example10();
</script>
</body>
</html>
JavaScript
Arguments
Arguments in JavaScript