Example of parameter passing in javascript Functions _ javascript skills

Source: Internet
Author: User
This section describes how to transmit parameters in javascript Functions. If you have any questions about parameter transfer, you may find yourself confused when passing function parameters, the reason is none. 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 call it? You can test ('Eric '), test ('Eric', 'Welcome to javascript ') you can even pass any number of parameters to it, and the type is random. this is a great thing. If you have studied c ++/c # or java, you may think of function overloading. However, what I want to tell you is that there is no function overload in javascript. If you define two functions with the same name, the first defined function will be overwritten by the second defined function, this means that the result you want can only be obtained from the function defined later.

Well, let's get down to the point. Why can javascript function transmission be so casual? Let's take a look at where all the passed parameters are stored. In fact, in its internal implementation, all the passed parameters exist in an array. The function always receives this array, regardless of the parameters contained in the array. Now we can understand it. We have defined a function. When calling this function, you can upload parameters as needed. If you do not upload any parameters, you can add them to the array, if all your parameters are 'undefined', there is no syntax error, but it is hard to say it in semantics.

All right, the first time I wrote a blog, I hope this blog post will 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.