arguments对象:当前函数内置的全局属性,表示当前函数的所有参数的集合可以用来检测函数实参的个数

使用环境:当函数的参数个数无法确定时,使用arguments

写一个函数输出arguments看看有什么

function fn(n1,n2,n3,n4,n5){
console.log(arguments,arguments.length);
}
fn();    //Arguments [callee: ƒ, Symbol(Symbol.iterator): ƒ] 0
fn(1,2,3)  //Arguments(3) [1, 2, 3, callee: ƒ, Symbol(Symbol.iterator): ƒ]

输出的是一个一个集合,没有实参的时候长度为0,有几个实参长度就是几

也可以用arguments[i]的方式获取第i+1个实参,如果是fn();没有实参的话,输出为undefined

//加入参数不确定,就利用arguments集合求和

function sum(){
var sm = 0;
for(var i=0;i<arguments.length;i++){
sm += arguments[i];
}
return sm;
}
console.log(sum(1,2,3));//6
//如果没有return返回值,函数就返回undefined
//arguments可以改变形参的值
function fn3(a) {
alert(a);//
var a = 2;
alert(a);//2,变量名和形参一样,后边的就会覆盖前边的
arguments[0] = 3;
alert(a);//3,上边给实参赋值,相当于给形参赋值
}
fn3(1);

JS的arguments的更多相关文章

  1. js参数arguments的理解

    原文地址:js参数arguments的理解 对于函数的参数而言,如下例子 function say(name, msg){ alert(name + 'say' + msg); } say('xiao ...

  2. js中arguments对象和this对象

    js中arguments对象和this属性 如果不注重复习,花时间准备的材料毫无意义 arguments对象和this对象都是对象 直接来代码 <!DOCTYPE html> <ht ...

  3. js function arguments types

    js function arguments types https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functi ...

  4. js中arguments的用法

    了解这个对象之前先来认识一下javascript的一些功能: 其实Javascript并没有重载函数的功能,但是Arguments对象能够模拟重载.Javascrip中国每个函数都会有一个Argume ...

  5. JS函数arguments数组获得实际传参数个数

    JS与PHP在函数传参方面有点不同,PHP形参与实参个数要匹配,而JS就灵活多了,可以随意传参,实参比形参少或多都不会报错. 实参比形参多不会报错 ? 1 2 3 4 5 function say(a ...

  6. js中arguments,caller,callee,apply的用法小结

    <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <style typ ...

  7. js中arguments的作用

    在javascript函数体内,标识符arguments具有特殊含义.它是调用对象的一个特殊属性,用来引用Arguments对象. Arugments对象就像数组,注意这里只是像并不是哈. javas ...

  8. js中arguments

    arguments 每天一对象,JS天天见,今天我们来看看arguments对象及属性.arguments对象不能显式创建,arguments对象只有函数开始时才可用.函数的 arguments 对象 ...

  9. js 中arguments,call,apply,bind的使用

    //对于 arguments和this, 每个函数都有自己独有的arguments和this, 且不进行链式查找 //arguments是什么? //答:1:arguments是收到的实参副本 //2 ...

  10. js的arguments到底是什么?

    类数组对象:arguments 总所周知,js是一门相当灵活的语言.当我们在js中在调用一个函数的时候,我们经常会给这个函数传递一些参数,js把传入到这个函数的全部参数存储在一个叫做arguments ...

随机推荐

  1. [Swift]LeetCode73. 矩阵置零 | Set Matrix Zeroes

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place. Exampl ...

  2. [SQL]LeetCode180. 连续出现的数字 | Consecutive Numbers

    SQL架构: Create table If Not Exists Logs (Id int, Num int) Truncate table Logs insert into Logs (Id, N ...

  3. [Swift]LeetCode234. 回文链表 | Palindrome Linked List

    Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false ...

  4. [Swift]LeetCode315. 计算右侧小于当前元素的个数 | Count of Smaller Numbers After Self

    You are given an integer array nums and you have to return a new countsarray. The counts array has t ...

  5. [Swift]LeetCode718. 最长重复子数组 | Maximum Length of Repeated Subarray

    Given two integer arrays A and B, return the maximum length of an subarray that appears in both arra ...

  6. [Swift]LeetCode827. 最大人工岛 | Making A Large Island

    In a 2D grid of 0s and 1s, we change at most one 0 to a 1. After, what is the size of the largest is ...

  7. [Swift]LeetCode982. 按位与为零的三元组 | Triples with Bitwise AND Equal To Zero

    Given an array of integers A, find the number of triples of indices (i, j, k) such that: 0 <= i & ...

  8. Python内置函数(49)——pow

    英文文档: pow(x, y[, z]) Return x to the power y; if z is present, return x to the power y, modulo z (co ...

  9. Zara带你快速入门WPF(1)---开篇

    一.引言 我们时常可以看到园友们在讨论WPF与WinForm!它们两个的激情对决,看到大家热情洋溢的评论,搞技术的我也是深受感动. 二.走势 但抱歉的是,我无法预测未来WPF会怎么样.乔布斯说过这么一 ...

  10. Python链接Mssql之Python库pymssql

    连接数据库 pymssql连接数据库的方式和使用sqlite的方式基本相同: 使用connect创建连接对象 connect.cursor创建游标对象,SQL语句的执行基本都在游标上进行 cursor ...