An example of parameter transfer problem in JavaScript functions _javascript tips

Source: Internet
Author: User

Believe that every one of the students just contact JavaScript in the function of the parameters of the transfer will be very confused, the reason for him, that is its syntax is too weird, you define a function

For example

function test (name,msg) {return
' Hello ' + name + msg;
}

So how do you tune it when you call it, you can test (' Eric '), Test (' Eric ', ' Welcome to JavaScript '), and even you can pass any number of arguments to it, and the type is random. It's such a wonderful thing to learn c++/c# Or a Java classmate might think of a function overload. But what I'm going to tell you is that there is no function overload in JavaScript, and if you define two functions with the same name, the function defined first will be overwritten by the later definition, meaning that the result you want can only be obtained from the function defined later.

Well, to go back to it, why is the function of JavaScript so random, so let's take a look at where the parameters are stored. In fact, in its internal implementation, all the passed arguments exist in an array. This array is always received by the function, regardless of what parameters the array contains. It's a good idea now, we have defined a function, when the parameters can be randomly transmitted, you pass how much it is to you into the array, if not, then your formal parameters are all ' undefined ', which does not have any grammatical errors, but the semantic is not easy to say.

Well,,,,,,,, for the first time to write a blog, little brother, let everyone laugh, I hope this blog can help you a little bit ....

I Love you,guys!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.