JavaScript -- typeof

Source: Internet
Author: User

In JavaScript, typeof is an operator used to detect the Data Type of a given variable. typeof is used to detect the Data Type of the following variable.

Example:

VaR m; var M1 = "hi"; var m2 = 2; var m3 = true; var M4 = function () {}; var M5 = new object (); vaR M6 = NULL; alert ("typeof M type:" + typeof m + "\ n \ r" + "typeof M1 type: "+ typeof M1 +" \ n \ r "+" typeof M2 type: "+ typeof M2 +" \ n \ r "+" typeof M3 type: "+ typeof m3 +" \ n \ r "+" typeof M4 type: "+ typeof M4 +" \ n \ r "+" typeof M5 type: "+ typeof M5 +" \ n \ r "+" typeof M6 type: "+ typeof M6 +" \ n \ r "+" typeof M7 type: "+ typeof M7 );

View results

Running result: When a variable is declared with VAR but not initialized, the value of the variable is undefined.

The variable value that is not declared is also undefined.

The data type of a null variable is of the object type, because the null value indicates a null object pointer.

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.