Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the arguments object in JavaScript function

Shulou Source: shulou.com Published: 2022-06-01 05:11:27 09月29日 Update

This article mainly explains "how to use the arguments object in the JavaScript function". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the arguments object in the JavaScript function".

Arguments object in JavaScript function

The JavaScript function has a built-in object called the arguments object.

The arguments object contains an array of parameters used when the function is called.

In this way, you can simply use functions to find, for example, the highest value in a list of numbers:

Example

X = findMax (1,123,500,115,44,88)

Function findMax () {

Var i

Var max =-Infinity

For (I = 0; I)

< arguments.length; i++) { if (arguments[i] >

Max) {

Max = arguments [I]

}

}

Return max

}

Or create a function to sum up all input values:

Example

X = sumAll (1,123,500,115,44,88)

Function sumAll () {

Var I, sum = 0

For (I = 0; I < arguments.length; iTunes +) {

Sum + = arguments [I]

}

Return sum

}

Parameters are passed by value

The parameter (parameter) in the function call is the parameter (argument) of the function.

The JavaScript parameter is passed by value: the function only knows the value, not the position of the parameter.

If the function changes the value of the parameter, it does not change the original value of the parameter.

Changes in parameters are not visible outside the function.

Thank you for reading, these are the contents of "how to use the arguments object in the JavaScript function". After the study of this article, I believe you have a deeper understanding of how to use the arguments object in the JavaScript function, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Function parameter object learning content instance original highest position that is train of thought sum situation number array article more maximum knowledge knowledge point Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux Microsoft Huawei MySQL