JavaScript syntax and type
First, type
1, built-in types (null, undefined, boolean, number, string, object, symbol (es6 new in)) (other than an object, referred to as other types of base);
It can be used to determine the type typeof value.
typeof undefined === "undefined"; //true
typeof true === "boolean"; //true
typeof 20 === "number"; //true
typeof "20" === "string";// true
typeof {life: 20} === "object"; // true object is a subtype
typeof [1,2,3] === "object"; a // true object of subtype
typeof Symbor () === "symbol"; // true es6 new type of
As typeof null === "object"; // true (it's a bug, but has not yet repair; if change overnight, many system does not work.)
Null value detection method of the type: var a = null; (a = typeof a === "object"!); // true; null is a sub-type of the object.
2, and the type value (no variables in JavaScript type, only the values only);
Typeof operator when performing variable, the variable type is not the type determination, but the variable holds the value. Type defines the behavior of the eigenvalues.
例: var a = 20; tyepeof a; //"number"
a = true; typeof a; //boolean;
typeof operator always returns a string: typeof typeof 42; // "string" typeof 20 first returns the character "number"; then typeof "number" return "string"
3、undefined 和 undeclared
In the variable declaration in scope but has no value is undefined; yet in the variable declaration of scope, it is undeclared
Example; var a; typeof a; // underfined typeof c; // ReferenceError c is not defined types are undefined but typeof
To be continued. . . . .