First, you must know that js has five basic data types: number, string, and logic (boolean, special data type: undefined) and null values (null). There are also three types
First, you must know that js has five basic data types: number, string, and logic (boolean, special data type: undefined) and null values (null). There are also three types of composite data: functions, objects, and arrays ).
When it comes to the detection data type, we can all think that typeof is a detection variable or a value operator. There is only one parameter!
Take a look at the following JavaScript code:
var a = "phpddt.com";var b = true;var c = 100;var d;var e = null;var f = new Object();alert(typeof(a)); //string alert(typeof(b)); //booleanalert(typeof(c)); //numberalert(typeof(d)); //undefinedalert(typeof(e)); //objectalert(typeof(f)); //object
From the result of running the js Code above, we can see that if the variable is an object or null, all returned types are objects. But sometimes, we need to know not only whether a data type is an object, but also what type of object it is!
OK. It is an important operator in js, instanceof. Its main functions are as follows:
1. determine whether an object is an array
2. Determine whether a variable is an instance of an object
Take a look at the following JavaScript code: