

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use unlimited arguments in a JavaScript function?
To use an unlimited number of arguments to function, use the arguments object.
Example
You can try to run the following code to implement unlimited arguments to a function in JavaScript
<html> <body> <script> function functionArgument(val1, val2, val3){ var res = ""; res += "Expected Arguments: " + functionArgument.length; res += "<br />"; res += "Current Arguments : " + arguments.length; res += "<br />"; res += "Each argument = " for (p = 0; p < arguments.length; p++){ res += "<br />"; res += functionArgument.arguments[p]; res += " "; } document.write(res); } functionArgument(20, 50, 80, "Demo Text!","Hello World", new Date()) </script> </body> </html>
- Related Questions & Answers
- How to use variable number of arguments to function in JavaScript?
- How to use variable-length arguments in a function in Python?
- How to use typeof with arguments in JavaScript?
- How to use named arguments in JavaScript functions?
- How to pass arrays as function arguments in JavaScript?
- How to use Spread Syntax with arguments in JavaScript functions?
- Passing unknown number of arguments to a function in Javascript
- How to use setTimeout() function in JavaScript?
- How do we use function literal to define a function in JavaScript?
- How to pass arguments by reference in a Python function?
- PHP Function arguments
- How to use setInterval function call in JavaScript?
- How to use jQuery.slice() method with no arguments?
- Tkinter binding a function with arguments to a widget
- How to pass arguments by value in Python function?
Advertisements