JavaScript variables, constants, function declarations

Source: Internet
Author: User

Declaring variables :

var= Let defines a variable, which can be used to declare a local variable of a block scope (block scope local variable). 

Declaring Constants :

keyword is  CONST Syntax: const  = 1.1313131, usually in theform of full capitalization of names, whose values are immutable and must be assigned when defined. 

Note: Variables defined with let or const do not have a "variable boost" and a "reference error" occurs if a variable is used before it is defined.

2 types of functions :

function GetName () {Execute code block;}

Note: Functions can have parameters or return values, or they can be taken without. If you have parameters, you need to add the corresponding parameters when calling the function. If there is a return value, you should provide a container (such as a variable) to receive the return value when the function is called.

Two: Function expressions (also called anonymous functions, popularly called functions without names) syntax: var function () {Execute code block;}

Note: In the above example, fun is the variable name, also the function name, when using fun equivalent to get the entire function body, when using fun () equivalent to call this function.

var function () {Console.log (111);} Fun ();

--"111

var bb = fun;console.log (BB);

--》

Note: function promotion, only the declarative (named) function can be promoted, the expression (anonymous) function is not promoted.

JavaScript variables, constants, function declarations

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.