Javascript example Tutorial: typeof Operator

Source: Internet
Author: User

Since ECMAScript is loose, there is a need to detect the Data Type of a given variable-typeof is the operator responsible for providing this convenient information. Using the typeof operator for a value may return one of the following strings:

"Undefined" -- if this value is not defined

"Boolean" -- if this value is a boolean Value

"String" -- if the value is a string

"Number" -- if this value is a numerical value

"Object" -- if this is an object or null

"Function" -- if this value is a function

Below are several examples of using the typeof OPERATOR:

Var message = "some string ";

Alert (typeof message); // "string"

Alert (typeof (message); // "string"

Alert (typeof 95); // "number"

These examples show that the operand of the typeof operator can be a message or a numeric literal. Note that typeof is an operator rather than a function, so parentheses in the example are not required (although they can be used ).

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.