Home > Article > Web Front-end > Detailed analysis of JavaScript variable types_javascript skills
Variable type
typeof,instanceof
var obj = null; console.info(typeof obj); //Object var arr = []; console.info(arr instanceof Object); //true console.info(arr instanceof Array); //true
Wapper Object of primitive data type
Data type conversion
console.log(parseInt("34", 10)); //34 console.log(parseInt("34s5b", 10)); //34 console.log(parseInt("s", 10)); //NaN console.log(parseInt(3.14, 10)); //3
//number var value = 100; //string value = "qiu"; //object value = [1, 'two', 3];
"="Various patterns of numbers:
because === Strict judgment and other
var x = 42; var y = "42"; console.log(x == y) //true; console.log(x === y) //false
Udefine: means the variable is undefined and does not have a valid value (there is no variable yet, so how can we talk about the value)
null: nothing, a variable does not refer to any object. null is an object, type object (has variables, but does not reference values)
var obj = null; if (obj === null) { alert("obj === null"); //此句将执行 } else { alert("obj!=null"); } alert(typeof obj); //object
var myVar; //true console.log(typeof myVar === "undefined"); console.log(myVar === undefined); var myVar2 = null; console.log(typeof myVar2); //object //true; console.log(myVar2 == null); console.log(myVar2 === null); //true console.info(myVar == myVar2); //undefine == null; 是true //false console.info(myVar === myVar2); //undefine === null; 是false
undefined, null,NaN,"",0
Except for these values, other values are true;
Operator: ! ! with ||
!! Convert the following expression into a boolean value and return true or false
!! "qiu"
var ns = ns || {}
If ns is undefined, return {}, otherwise return ns
Note: You must use var to define variables, otherwise you will get stuck! If you don’t write var, it will become a global variable
The above is the entire content of this article, I hope you all like it.