Home > Web Front-end > JS Tutorial > body text

Discussion on Examples of Parameter Passing Problems in JavaScript Functions_Javascript Skills

WBOY
Release: 2016-05-16 16:40:33
Original
1221 people have browsed it

I believe that every student who is new to JavaScript will be confused about passing function parameters. The reason is that its syntax is too weird. You define a function

For example

function test(name,msg){
return 'hello' + name + msg;
}
Copy after login

So how do you adjust it when calling? You can test('Eric'), test('Eric','welcome to javascript') or even you can pass as many parameters to it, and the types are arbitrary. This What a cool thing. Students who have studied C/C# or Java may think of function overloading. However, what I want to tell you is that there is no function overloading in JavaScript. If you define two functions with the same name, then the function defined first will be overwritten by the one defined later, which means that the result you want can only be obtained from the later one. obtained from the defined function.

Okay, let’s get back to the topic, why can JavaScript function transfer be so casual? Let’s first take a look at where the passed parameters are stored. In fact, in its internal implementation, all passed parameters are stored in an array. What the function receives is always this array, regardless of what parameters the array contains. Now it’s easy to understand. We have defined a function. When calling, you can pass any parameters. It will add them to the array for you. If you don’t pass them, then all your formal parameters will be 'undefined'. This is not true. There may be some grammatical errors, but it’s hard to say semantically.

Okay,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, I am the first time I write a blog, I am so incompetent, I made everyone laugh, I hope this blog post can be of some help to you. . . .

I LOVE YOU,GUYS!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!