First, the TypeOf operator function:
Is the data type used to detect variables. Using the typeof operator for a value or variable returns the following string.
Ii. judgment of various data types
1, undefined: variable defined but not initialized, is undefined
var box;alert (box); // undefinedalert (typeof box); // box is the undefined type, the value is undefined, and the string returned by the type is also undefined
2. Boolean:
var true ; alert (Boxboolean); // truealert (typeof Boxboolean); // Boxboolean is a Boolean, the value is true, and the string returned by the type is also a Boolean
3. String:
var boxstring = ' Obama '; alert (boxstring); // Obama alert (typeof boxstring); // boxstring is a string type, the value is ' Obama ', and the type returned
4. Number:
var boxnumber = +; alert (boxnumber); // alert (typeof Boxnumber); // Boxnumber is the number type, the value is 100, and the string returned by the type is
5. Object:
//An empty object that indicates that the object was created, but there is nothing inside .varBoxobject = {};//an empty object was createdalert (boxobject);//[Object Object]AlerttypeofBoxobject);//Boxobject is an object type, the value is [Object Object], and the string returned by the type is also an object varBoxobject =NewObject ();//an empty object was createdalert (boxobject);//[Object Object]AlerttypeofBoxobject);//Boxobject is an object type, the value is [Object Object], and the string returned by the type is also an object//null object, which means no creation, is a nullvarBoxnull =NULL; alert (boxnull); //null or nothing there's only one windowAlerttypeofBoxnull);//Boxnull is a null type, the value is null or nothing, the string returned by the type is also an object, and null is derived from Object
6. Function:
function boxfunction () { }alert (boxfunction); // print out the main body alert (typeof boxfunction); // Boxfunction is the function value is the Boxfunction () {}, and the string returned by the type is function
The function is an object in ECMAScript, not a data type. Therefore, it is necessary to use TypeOf to distinguish between function and object.
7. The typeof operator can manipulate variables, and can also manipulate literal values. While this can also be used: typeof (Box), typeof is an operator rather than a built-in function.
// can be directly on the value (literal) with typeofalert (typeof ' Obama '); // string
typeof operator for JavaScript