[Javascript] // Numbers typeof37 = 'number'; typeof3.14 = 'number'; typeofMath. LN2 = 'number'; typeofInfinity = 'number'; typeofNaN = 'number'; // Despite being "Not-A-number" typeofNumber (1) === 'number'; // but never use this form! // Strings typeof "" = 'string'; typeof "bla" = 'string'; typeof (typeof1) = 'string '; // typeof always return a string typeofString ("abc") === 'string'; // but never use this form! // Booleans typeoftrue = 'boolean'; typeoffalse = 'boolean'; typeofBoolean (true) = 'boolean'; // but never use this form! // Undefined typeofundefined === 'undefined'; typeofblabla === 'undefined'; // an undefined variable // Objects typeof {a: 1 }== 'object '; typeof [1, 2, 4] === 'object'; // use Array. isArray or Object. prototype. toString. call to differentiate regular objects from arrays typeofnew Date () = 'object'; typeofnull = 'object'; typeofnew Boolean (true) = 'object '; // this is confusing. don't use! Typeofnew Number (1) === 'object'; // this is confusing. Don't use! Typeofnew String ("abc") === 'object'; // this is confusing. Don't use! // Functions typeoffunction () {}== 'function'; typeofnew function () === 'function'; typeofMath. sin = 'function'; as shown in the preceding example, typeof cannot determine the array and null, and it cannot determine the type of objects generated using the new operator. As for instanceof, because in JavaScript, all objects are objects, that is, the new Number (2) or new String ('hello') is also an object, so it cannot be determined. However, Object. prototype. toString will always return such a string "[object class]" for any variable, and this class is the name of the constructor of the JavaScript embedded Object. For User-Defined variables, class is equal to object. Therefore, Object. prototype. toString. apply (obj) can be used to accurately obtain the variable data type. The data types obtained through Object. prototype. toString include Date, Object, String, Number, Boolean, Regexp, Function, undefined, null, and Math.