JavaScript program development (5) - js syntax

statement

A statement in js ends with a semicolon, but the semicolon can be omitted. If the semicolon is omitted, the parser determines the end of the statement. As shown in the following code:

	var c = a + b
	return c
	var c = a + b;
	return c;
The above two ways are correct sentence writing, but the former one is not recommended. Because adding a semicolon can avoid many errors, and developers can also compress code files by removing extra spaces (if there is no semicolon when doing so, it will cause compression errors), and adding a semicolon can increase the readability of the code .

When writing js code, you can use the C style to combine multiple statements into a code block, that is, start with an opening brace ({) and end with a closing brace (}). As shown in the following example:

function load(a,b){
	var c = a + b;
	return c;
}
One thing to pay attention to when applying the code block combination statement is that in the conditional control statement, if the code block is used when executing multiple statements, we all understand this, but when only one statement is executed, someone Tends to use the code block way, some people don't think so. However, I prefer to use the code block form whether executing multiple statements or a single statement, because it makes the code clearer and reduces the chance of errors when modifying the code. I remember a friend talking about a bug when he wrote the code, but he didn't find it out after a long time of investigation. Later, when he found a conditional control statement, he found that a single execution statement did not use a statement block, so he changed it to a statement block. After the form, the program is passed. That is C language. This tells us that it is not necessarily wrong when the code block is not applicable, but it must not be wrong when the code block is applicable. In order to make our program stronger, why not do it.

Keywords and reserved words

ECMA-262 specifies a set of specific-purpose keywords that can be used to indicate the start and end of control statements, or to perform specific operations, etc. As a rule, keywords are also reserved by the language and cannot be used as identifiers. Here are the full list of ECMAScript keywords:

	break      else      new      var
	case       finally   return   void
	catch      for       switch   while
	continue   function  this     with
	default    if        throw
	delete     in        try
	do         instanceof typeof

ECMA-262 also specifies a set of reserved words that, although they have not been used for any specific purpose so far, they may be of great use in the future. The following are all reserved words of ECMA-262 3rd Edition:

	abstract   enum       int        shor
	boolean    export     interface  static
	byte       extends    long       super
	char       final      native     synchronized
	class      float      package    throws
	const      goto       private    transient
	debugger   implements protected  volatile
	double     import     public


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325758698&siteId=291194637