Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge
  • All
  • C#
  • MVC
  • Web API
  • Azure
  • IIS
  • JavaScript
  • Angular
  • Node.js
  • Java
  • Python
  • SQL Server
  • SEO
  • Entrepreneur
  • Productivity

JavaScript Arguments Object

Use the built-in arguments object to access all the parameters of a function inside a function.

The arguments object is an array-like object. You can access its values using an index similar to an array. However, it does not support array methods.

Example: Arguments Object
function displayMessage(firstName, lastName) {
    alert("Hello " + arguments[0] + " " + arguments[1]);
}

displayMessage("Steve", "Jobs"); 
displayMessage("Bill", "Gates");
displayMessage(100, 200);
Try it

The arguments object is still valid even if a function does not include any parameters.

Example: arguments Object
function displayMessage() {
    alert("Hello " + arguments[0] + " " + arguments[1]);
}

displayMessage("Steve", "Jobs"); // display Hello Steve Jobs
Try it

An arguments object can be iterated using the for loop.

Example: Access all Parameters
function displayMessage() {

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

displayMessage("Steve", "Jobs");
Try it

It is recommended to use rest parameters instead of the arguments object because the rest parameters provide a cleaner syntax and are easier to work with.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.