Basic knowledge of JavaScript function mode-js tutorial

Source: Internet
Author: User
This article gives a detailed explanation of the four functional modes of javascript and attaches examples to help you understand and apply them. In javascript, a function is a type of object, which means that it can be passed to other functions as a parameter. In addition, a function can also provide a scope.

Basic javascript Functions: javascript learning notes (4) function

Syntax for creating a function

Name function expression

The Code is as follows:


// Name function expression
Var add = function add (a, B ){
Return a + B;
};

Function expression

The Code is as follows:


// Also known as anonymous Functions
Var add = function (a, B ){
Return a + B;
};

Function Declaration

The Code is as follows:


Function foo (){
// Code here
} // You do not need a semicolon here

In the trailing semicolon, the function expression should always use the semicolon, and the declaration of the function does not need to end with the semicolon.

Function declaration and Expression

Hoisting)

The behavior of the function declaration is not equivalent to the name function expression. The difference is that the hoisting behavior. See the following example:

The Code is as follows:


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.