JavaScript (i): basic introduction to JavaScript and basic syntax

Source: Internet
Author: User
Tags hosting

What is JavaScript?

JavaScript is a literal script language, which is a dynamic type, a weak type, and a prototype-based language. (The so-called "scripting language": it means that it does not have the ability to develop an operating system, but a script to write large applications!) )

JavaScript itself does not provide any APIs related to I/O (input and output), which are provided by the hosting environment!

Common Hosting Environment: 1. Browser; 2. Server, node project.

The hosting environment is a browser, and the additional APIs provided are mainly three categories: 1. Browser Control class (Operation browser), 2.DOM class (the element that operates the Web page), 3.web class (for Internet function)

If the hosting environment is node, provide the API: File operations API, network communication API, and so on.

JavaScript history:

The relationship between JavaScript and the International Organization for Standardization ECMA(European Computer Manufaturers Association):

The summary is: ECMAScript is JavaScript specifications, standards; JavaScript is the implementation of the ECMA!

ECMAScript is just the basic grammatical structure used to standardize JavaScript, and the standards related to the deployment environment are defined by other standards, such as the DOM standard set by the world-Class!

ECMAScript's release:

December 2009, ECMAScript 5.0 released;

June 2011, ECMAScript 5.1 released;

June 2015, ECMAScript 6 was released and renamed "ECMAScript 2015"

For more on JavaScript history, refer to Ruan Yi Feng Tutorial

Related events: can be consulted

JavaScript variables:

1;//no meaning, no error2;;;//empty statement, no error3 varA=1;//It is recommended to always use VAR to declare variables! 4B=1;//Global variables are always created5 //Console.log (A + "" +b);6 Console.log (A, b);7 DeleteA//Delete is not valid8 Deleteb//Delete succeeded9 Console.log (a);TenConsole.log (b);//at this point B is deleted, error

Operation Result:

Variable elevation:

The JavaScript engine works by first parsing the code, getting all the declared variables, and then running it one line at a line.

The result is that declaration statements for all variables are promoted to the head of the code . This principle is called variable elevation (hoisting)

1 // equivalent to Var C; Console.log (c); c=1; 2 Console.log (c); 3 var c=1; 4 5 Console.log (d); 6 d=10;

Operation Result:

Undefined: Indicates that variable C has been declared, but is not assigned !

D is not definded: Indicates that the variable D was not declared . (d is not a var command stating that the JavaScript engine will not elevate it!) )

Comments:

Single-line comment://

Multiline Comment:/* * /

Historically, because JavaScript is compatible with HTML code annotations, <!-- and --and is also considered a single-line comment (this is not recommended by individuals!). )

1 <!-- Here you can write a comment 2  --and here you can write the comment, the comment symbol must be at the beginning! Otherwise it will error, or be treated as operator 3var e=1; 4 if (e-->0) {// equivalent to e-->05     Console.log (e);   Output 06 }

Block:

The statement that is included with curly braces is block (block).

Note: JavaScript chunks do not form a separate scope (scope). That is, the variables in the chunk and the variables outside the block belong to the same scope! (c + + and other languages this situation will be an error!) )

1  for (var i=0;i<5;i++) {2    console.log (i); 3 }4 console.log (i); // Output 5

switch:(use strict equality operator = = = comparison!) )

1 varX=1;2 Switch(x) {3      Case true:4Console.log (' first step '));5          Break;6      Case false:7Console.log (' Second Step '));8     default:9Console.log (' = = = Strict equality operator used in ' switch '));Ten          Break; One}

Operation Result:

Break and Continue statements : (default only for one layer of loops !) (Loops refer to while and for loops, etc.)

Break: Jump out of the loop!

Continue: Immediately terminate this round loop, return to the loop structure head, start the next cycle!

1 varz=10;2  while(z<=10){3z--;4     if(z===9){5         Continue;//Jump to z--6}Else{7 Console.log (z);8     }9     if(z===8){Ten Console.log (z); One          Break;//jump to while outside A     } -}

tags : JavaScript statements can be preceded by a label (label), equivalent to a locator, to jump to the appropriate location.

1Abc://can be arbitrarily named, without the need to add quotation marks2      for(j=0;j<3;j++){3          for(k=0;k<=j;k++){4             if(K===j && K===1)5                  Breakabc//jump out of these two layers of loops! 6             Else7Console.log (j+ "" +k);8         }9}

Similarly: Continue can also be tagged behind! When the condition is met, skip the current loop and go to the next outer loop ; If the continue is not labeled later, it can only go into the next layer of inner loop!

This article refers to the link: Nanyi JavaScript standard reference Tutorial

JavaScript (i): basic introduction to JavaScript and basic syntax

Related Article

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.