1. Data type
JS data type Total 6 kinds
respectively:
Numeric, String, Boolean, Undefind,null, object the most basic data types are 3 kinds: numeric, String, and Boolean objects can be divided into 3 subtypes: narrow objects, arrays, functionsnarrow arrays and objects are two different ways of combining data. And the function is actually the method of processing the data. JS treats functions as a data type that can be assigned and passed like other types of data2. Data type judging three methods of judging
> typeof> instanceof> Object.ptototype.toString ()
Experimental data and return values
typeof 123 "number" typeof ' 123 ' "string" typeof false "Boolean" function f () {}typeof F "function" typeof undefined " Undefined "typeof v" undefined "typeof Window" Object "typeof {}" Object "typeof []" object "typeof Null" Object "var arr = []; Console.log (Object.prototype.toString.call (arr)) vm1072:2 [Object array]var arr = {};console.log ( Object.prototype.toString.call (arr)) Vm1075:2 [Object Object]
3.null and undefinded
null
And undefined
both can say "no", meaning very similar
The distinction between null and Undefindednull is an object that represents none, and a value of 0;undefined is a primitive value that represents none, and a value of NaN4 when converted to a number. Boolean conversion rule: except for the following six values are converted to
false
, other values are considered
true
。
Undefinednullfalse0nan "" or "(empty string)
[]
the Boolean value corresponding to the empty array () and the empty object ( {}
) aretrue
if ({}) {Console.log (' empty object is true ');} Vm1115:2 Empty object is Trueif ([]) {Console.log (' empty array is true ');} Vm1118:2 empty Array is true
This blog post learns from Nanyi's JavaScript standard reference tutorial (Alpha)
JavaScript Learning notes-data types