This article is NetEase Cloud classroom Jin Xu-liang Teacher's course note, records down, to prepare for forgetting.
Variable Type
There are only 6 kinds: four raw data Types Boolean, number, String, undefine, and other object,function are objects
Typeof,instanceof
See examples directly:
var NULL ; Console.info (typeof obj); // Object var arr = []; instanceof Object); // true instanceof Array); // true
wrapper objects for raw data types (Wapper object) String,number,boolean all correspond to specific packaging objects
Data type Conversions Convert to numeric type with Parseint,parsetfolat
// the // the // NaN // 3
JavaScript is
Dynamic TypeProgramming language, the same variable, what type of data to grab what kind of variable type
// Number var value = +//stringvalue = "Qiu"//Objectvalue = [1 , ' both ', 3];
various patterns of the "=" Number:
= = Assignment = = = , etc. = = = Strict judgment such as var x =; var y = "x"//true; // false
undefined vs nullUdefine: Refers to the variable is undefined, there is no valid value (not yet variable, what from the talk value) Null:nothing, a variable does not refer to any object. Null is an object, type object (with variable, but no reference value)
var NULL ; if NULL {alert (// This sentence will be executed }else {alert ("Obj!=null");} Alert (typeof//Object
Undefine and null judgments, etc.
varMyVar;//trueConsole.log (typeofMyVar = = = "undefined"); Console.log (MyVar===undefined); varMYVAR2 =NULL; Console.log (typeofMYVAR2);//Object//true;Console.log (MyVar2 = =NULL); Console.log (MyVar2===NULL); //trueConsole.info (MyVar = = myVar2);//undefine = = null; is True//falseConsole.info (MyVar = = = MyVar2);//Undefine = = = NULL; is False
true and False Undefined, Null,nan, "", 0
In addition to these values, the other values are true;
operator:!! with | |!! Convert the following expression to a Boolean value that returns TRUE or FALSE! " Qiu "True!! Null false | | var ns = NS | | {} If NS is not defined to return {}, the NS note is returned:
define variables must be VAR, otherwise drop pits! If you do not write Var, it will become a global variable .
JavaScript I learn a variable type