JavaScript's typeof operators and data types

Source: Internet
Author: User
Tags object object

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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.