Friday, December 24, 2021
In JavaScript when you define a function you get a built-in Arguments object, this object is an array-like object that puts the arguments/parameters of the your function in an object which can be accessed via indexes much like an array.
This can be useful if you have a function that takes multiple parameters, but you don't know how parameters there will be. Let's modify our addNumbers function so that it can add more than two numbers using the Arguments object.
If you remember our previous addNumbers function it only takes two numbers and and add them.
With no parameters specified we can specify as many parameters as we want and add the numbers based on the number of parameters to get the total. The draw back with this approach is that we don't have any named parameters, which means that we can only to the parameters via the arguments object like this argument[i]. However, we don't have to know the exact number of parameters ahead of time for our function. So there is a trade-off.
This can be useful if you have a function that takes multiple parameters, but you don't know how parameters there will be. Let's modify our addNumbers function so that it can add more than two numbers using the Arguments object.
<script> function addNumbers() { var sum = 0; for (var i = 0; i < arguments.length; i++) sum += arguments[i]; return sum; } console.log("The sum of the numbers are " + addNumbers(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); </script>
If you remember our previous addNumbers function it only takes two numbers and and add them.
With no parameters specified we can specify as many parameters as we want and add the numbers based on the number of parameters to get the total. The draw back with this approach is that we don't have any named parameters, which means that we can only to the parameters via the arguments object like this argument[i]. However, we don't have to know the exact number of parameters ahead of time for our function. So there is a trade-off.
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
really very useful information given by you. this post is very informative. the article is nicely explained and easy to understand. thanks for sharing this post with us.
ReplyDeletehttps://www.milanosrenfrew.uk/
ReplyDeleteThis article having so much of amazing information. Today I learned so many things in this blog post.
Keep doing your awesome work>
Casinos & casinos | Microgaming | Microgaming
ReplyDeleteMicrogaming Casino 예스 벳 88 | Microgaming 스포츠분석 | 스코어사이트 Microgaming is the leading 인터넷 바카라 casino software provider, 룰렛 돌리기 게임 offering innovative games, a variety of table games and a
Great article! Your insights are valuable, and it's evident that your team is well-versed in creating tailored solutions. I appreciate the straightforward explanations. If anyone is seeking reliable Custom web development services, they should definitely consider reaching out to our team. Keep up the good work!
ReplyDelete