Advanced JavaScript program chapter study notes --3,4

JavaScript basic concepts, variables, scopes and memory problems

basic concept

Identifier

The so-called identifier refers to the name of variables, functions, properties, or the parameter of the function. Composition rules are as follows:

  •  The first character must be a letter, underscore (_) or a dollar sign ($);
  •  other characters can be letters, underscores, dollar signs or numbers.

ECMAScript identifiers using camel case format, which is the first letter of the first letter lowercase, and the rest of each word capitalized. Javascript syntax is strictly case-sensitive.

Note

ECMAScript C-style comments, including single-line and block comment. Single-line comments begin with two slashes as follows:
one-line comment //
block comment begin with an asterisk and a slash (/ *), end with a slash and an asterisk (* /), as follows shows:
/ *
* this is a multi-line
* (block level) Note
* /
while the second and third rows of the above comments start with an asterisk, but this is not required. Add two asterisks that reason, purely for readability comments (most often in this format with enterprise applications).

Strict Mode (Key)

ECMAScript 5 introduces strict mode (strict mode) concept. And some unsafe operation will throw an error. To enable strict mode in the whole script, you can add the following code at the top:

"use strict";

Keywords and reserved words

5th edition the reserved word run in non-strict mode is reduced to following these:
  class enum the extends Super  const Export Import
in strict mode, 5th edition has also put restrictions on the following reserved words:
  the implements Package Penalty for public  interface Private static  the let protected yield
note, let and yield is the fifth version of the new reserved word;

variable

ECMAScript variables are loose type is the so-called bulk type can be used to store any type of data. In other words, each variable is just a placeholder for storing values only.
Global variables and local variables: simple and can be understood as a variable declared outside a function are global variables , declared in the function of local variables.

Useful knowledge exam: js variables, there are two scopes?

A : global and local variables. Var declared variable is not used outside the function declaration and variables are global variables is one window attribute; var variables declared in a function where belong, regardless of which appear in function of position, equivalent to the beginning of the function statement. Local variables a higher priority than global variables of the same name, the local variable hides the global variable of the same name. To access the hidden global variables plus the window. Prefix.

Special global variables:

function test(){
message = "hi"; // global variables
}

Examples var operator is omitted, and thus it becomes a global variable message. In this way, just call once test () function, this variable will have a defined, can be accessed at any place outside the function, a test () function is not called message how to undefined.

 

 

 

Guess you like

Origin www.cnblogs.com/tuBoss/p/10926627.html