Examples of parameter passing in javascript Functions and javascript examples

Source: Internet
Author: User

Examples of parameter passing in javascript Functions and javascript examples

I believe that every new javascript contact will be confused when 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;}

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!


Parameters passed by javascript Functions

You write B as a function here. If you do not call it, it will not run.
But according to the syntax, It is not passed in.
The parameter in the () defined by function is actually in the function body. It is equivalent to defining a private variable in the function body. If no closure is available, the variable with the same name is replaced.
You do not need to write parameters directly.
Function a (e ){
Function B (){
Alert (e );
}
B ();
}
A ('abc ');
In this way, e in function B is actually referenced to the scope of a, because B does not define this variable, it will look up a scope. (If the window scope is not found, if the variable is assigned, a variable will be created in the window scope. If the variable is used, an error will be reported: The variable does not exist ,)

Function calling in javascript is a parameter passing problem.

Onclick = "save_Eff ('<% = str %>')" Pay attention to the quotation marks. In this way, the html format is save_Eff ('20140901') and string.


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.