JS Function Basics

Source: Internet
Author: User

There are two common function declarations: declarative functions, expression functions

1. Declarative functions: Function Add (A, b) {

return a+b;

}console.log (add);//Return 3

2, the expression of the function (after the end of the statement will be added ";")

var saysomething=function (a) {

Console.log (a)

};saysomthing ("Hello World")

Second, immediately execute the function:! function () {Console.log ("the");} ();

The parameter passed in when the function is called is called an argument, and the parameter when declaring the function is a formal parameter.

Four, the variable increase: 1, find Var defined variables.

2, find the function of the declaration type:

var add=function (A, b) {

return a+b;}

Console.log (ADD)

When pre-parsing, the browser parses the variables defined by VAR, assigns the undefined to the variable, and then parses the declarative letter

Number

V. Scope of functions: global scope, local scope (scope of function)

var a=2;

function test () {var a=1;} Console.log (a)//return 2

function test () {var a=1;console.log (a)}//returns 1

Global variables work globally, local scopes are function scopes, and the values of variables only function locally.

The basic data types are stored in the stack, object types are stored in the heap, object types are address-passing, basic types

is a value pass.

JS Function Basics

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.