当前位置:网站首页>Simple understanding of arguments in JS
Simple understanding of arguments in JS
2022-04-23 09:22:00 【Small white egg tart】
stay js Each function in has a built-in object ,arguments, It can replace any formal parameter , For example, without knowing the number of parameters .
arguments Is a special object , His attribute names are in the order of the parameters passed in , have access to arguments[i],i=0,1,2,3... And he has length attribute , Store the number of currently passed in parameters , You can think of it as a class array object , But not an array . As can be seen from the following procedure .
Three formal parameters were passed in , Namely 1,2,3, Separated by commas , Then we printed it arguments The type of object, And then use for Loop traverses three formal parameters .
And pay attention to fn(1,2,3) and fn([1,2,3]) The difference between
function fn() {
console.log(arguments);
console.log(typeof arguments);
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
fn(1, 2, 3);

Each comma is used to represent a formal parameter ,fn([1,2,3]) Indicates that what is passed in is a formal parameter , therefore arguments.length=1, Only arguments[0]=[1,2,3] Indicates that this array is a formal parameter , therefore arguments[1] for undefined.
function fn() {
console.log(arguments);
console.log(typeof arguments);
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
console.log(arguments[1]);
console.log(arguments.length);
}
// fn(1, 2, 3);
var a = [4, 5, 6];
console.log(a.length);
fn(a);

版权声明
本文为[Small white egg tart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624114450.html
边栏推荐
- MySQL - Chapter 1 (data types in MySQL)
- Codeforces Round #784 (Div. 4)
- STM32 and FreeRTOS stack parsing
- npm ERR! network
- Program, process, thread; Memory structure diagram; Thread creation and startup; Common methods of thread
- SAP 101K 411K 库存变化
- [in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)
- JS prototype chain
- Go language learning notes - structure | go language from scratch
- EmuElec 编译总结
猜你喜欢

nn. Explanation of module class
![[in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)](/img/c9/43a63f526068ef6a3e4964a22c5a1f.png)
[in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)

【SQL server速成之路】数据库的视图和游标

Flink SQL realizes the integration of stream and batch

ATSS(CVPR2020)

SAP 101K 411k inventory change

Brush classic topics

《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路

The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution
![3、 6 [Verilog HDL] gate level modeling of basic knowledge](/img/36/46f2413ecb12f81c003848c93f6bc9.jpg)
3、 6 [Verilog HDL] gate level modeling of basic knowledge
随机推荐
Emuelec compilation summary
Resource packaging dependency tree
Vivo, hardware safe love and thunder
[58] length of the last word [leetcode]
LeetCode 1611. The minimum number of operations to make an integer 0
Employee probation application (Luzhou Laojiao)
小程序报错 :should have url attribute when using navigateTo, redirectTo or switchTab
ALV树(LL LR RL RR)插入删除
JS prototype chain
RSA 加密解密签名验签
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
Go language learning notes - slice, map | go language from scratch
kettle实验
STM32 and FreeRTOS stack parsing
108. Convert an ordered array into a binary search tree
The crawler returns null when parsing with XPath. The reason why the crawler cannot get the corresponding element and the solution
Four pictures to understand some basic usage of Matplotlib
ATSS(CVPR2020)
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
Matlab draw five-star red flag