Home  >  Article  >  Web Front-end  >  Code analysis on function parameters in JavaScript

Code analysis on function parameters in JavaScript

黄舟
黄舟Original
2017-10-27 09:37:051325browse

When writing a function in js, its parameters are internally represented as an array. That is to say: when we define a function, the parameters inside have nothing to do with the actual parameters passed in when calling this function in the future. If we want to define a function functionName(){}, the function itself has no parameters when it is defined. Yes, but we can pass in many parameters when calling this parameter, and inside the function, we can use the object of arguments to access the parameters:

function funcName() {
    for (var  item=0 ;item< arguments.length;item++) {
        console.log(arguments[item]);
    }
}
funcName("first", "second");

The above is the detailed content of Code analysis on function parameters in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn