Js object-oriented learning note 6 (variable)
[1. boolean corresponding to the value]
False Boolean value false object null number NaN (not a number) number 0 Initial Value undefined empty string "" true string "0" or other non-above six values
[2. Differences between null and undefined]
Null is actually an empty object or an array undefined. It is a declared or undeclared variable, but the initial value of the variable is not assigned. Therefore, no undefined object has no initial value without var declaration. the variable values are all undefined.
[3. Types of detection variables]
var a; typeof(a) ; //undefined var a = "0"; typeof(a) ; //string var a = 0; typeof(a) ; //number var a = null, b = new Array(1,2,3); typeof(a) ; //object typeof(b) ; //object var a= function(){ alert(12); } typeof(a) ; //function
[Note:] all variables must be declared using var before they are used.
Check whether the variable has if (typeof (somevar )! = "Undefined") {// exist coding here ...}
[Maximum value in 4. js]
Var maxnumber = Infinity; // note that Infinity is a built-in constant var minnumber =-Infinity; // the smallest negative js number.
[5. Scope of variables]
Var a = 123; function f () {alert (a); // undefined var a = 2; alert (a); // 2}; f (); // For The First Time: Variable scan is not assigned a value // for the second time: sequence assignment and execution