JavaScript method definition

Source: Internet
Author: User

There are three methods for defining Javascript methods.

One method is to define functions in Java, such as function (){}. Function is the keyword, and a is the function name.

The second method uses a Direct Volume definition, for example, var a = function (){}. Function, VaR is the keyword, and a is the function name.

The third method is to upload the parameter list and function bodies to the function as parameters, such:
VaR A = new function ("X", "Return x + X ");
Alert (A (2 )) 

If you want to set a default value for the parameter in the method, you need to write the code: Function C (a, B) {If (typeof (A) = "undefinded") A = 1 ;} Or:A =? A: 1
In the function, you can use the keyword arguments to obtain all the passed parameters.
Function f (){
Alert (arguments. length)
}
F (1, 2, 3, 4, 5)
Built-in functions of JavaScript, global fast: Parseint: resolved to a number Isnan: determines whether it is a number. Parsefloat: resolved to floating point type Escape: Encrypted string Usescapse: decrypts encrypted strings Eval: can execute the correct code in string format Eval ("alert ('abc ')")

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.