typeof operator: The typeof operator is the data type used to detect variables. Using the typeof operator for a value or variable returns the following string.
1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" />5 <title>Data type</title>6 <Scripttype= "Text/javascript">7 /*8 var box;9 alert (box);//undefinedTen alert (typeof box),//box is the undefined type, the value is undefined, and the string returned by the type is also undefined One A - var Boxboolean = true; - alert (Boxboolean);//true the alert (typeof Boxboolean);//boxboolean is a Boolean, the value is true, and the string returned by the type is also a Boolean - - - var boxstring = ' Obama '; + alert (boxstring);//Obama - alert (typeof boxstring);//boxstring is a string type, the value is ' Obama ', the string returned by the type is also + A var boxnumber = +; at alert (boxnumber);//100 - alert (typeof Boxnumber),//boxnumber is the number type, the value is 100, and the string returned by the type is - - //Empty object that indicates that the object was created, but there is nothing inside . - //null object, indicating that it is not created, is a null - var boxobject = {};//created an empty object in alert (boxobject);//[object Object] - alert (typeof Boxobject),//boxobject is the object type, the value is [Object Object], and the string returned by the type is also an object to + var boxobject = new Object ();//Create an empty object - alert (boxobject);//[object Object] the alert (typeof Boxobject),//boxobject is the object type, the value is [Object Object], and the string returned by the type is also an object * $ var boxnull = null;Panax Notoginseng alert (boxnull);//null or nothing. There's only one window. - alert (typeof boxnull),//boxnull is a null type, the value is null, or nothing, the string returned by the type is also an object the + A function Boxfunction () { the + } - alert (boxfunction);//print out the main body $ alert (typeof boxfunction);//boxfunction is the function value is the body functions boxfunction () {}, the string returned by the type is function $ */ - //you can use typeof directly on the value (literal) - Alert (typeof 'Obama');//string the </Script> - </Head>Wuyi the <Body> - Welcome to the world of JavaScript Wu </Body> - </HTML>
The typeof operator can manipulate variables or manipulate literal values. Although this can also be used: typeof (Box), typeof is an operator rather than a built-in function. PS: The function is an object in ECMAScript, not a data type. Therefore, it is necessary to use TypeOf to distinguish between function and object.