Four ways to define a declarative function in JavaScript

Source: Internet
Author: User

Four ways to define a declarative function in javascript: http://blog.163.com/zzf_fly/blog/static/209589158201286104927248/

Method One: function functionname ([parameters]) {functionbody};

Method Two: Assign an unnamed functional function to a specified variable (var): Var add=function (A, b) {}

Method Three: Use the new operator to declare functions varname=new function ([Param1name, Param2name,... paramnname], functionbody);

Method Four: Write the JavaScript code directly in the middle of the html/jsp code:

For example: In a hyperlink:

<href= "#"  onclick= "[javascript:] var booleanvalue = confirm (' Mid-Autumn Festival holiday?? '); alert (' result = ' +booleanvalue); >Click</a>

Four ways to define a declarative function in JavaScript

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.