JavaScript type judgment

Source: Internet
Author: User

Objective:

The new colleague asked me how I could tell if the undefined variable exists, the first thought is a! = undefined, but this is obviously wrong, and should be detected using typeof

typeof is an operator, the operand can be of any type, and the return value is a string.

    • Undefined-If the variable is of type undefined
    • Boolean-If the variable is of type Boolean
    • Number-If the variable is of type number
    • String-If the variable is of type string
    • Object-If the variable is a reference type or a Null type

Note: Here again involves javascript5 big data types, looking for data, in the relationship between ECMAScript and JavaScript on the bar ...

After seeing the implementation of JavaScript, I understand that ECMAScript is a standard that defines all the properties, methods, and objects of a scripting language. JavaScript is made up of ECMAScript, Dom, and BOM.

The DOM (Document Object model) is an application interface (API) for HTML and XML. The DOM will plan the entire page into a document composed of node hierarchies.

The BOM mainly deals with browser windows and frames, but usually browser-specific JavaScript extensions are considered part of the BOM. These extensions include:

    • Pop up a new browser window
    • Move, close, and resize a browser window
    • Anchor object that provides details about the Web browser
    • Screen object that provides detailed information about the user's screen resolution
    • Support for Cookies

IE expands the BOM, joins the ActiveXObject class, and can instantiate ActiveX objects through JavaScript

Reference Links:

Translation Use of javascript:typeof

Implementation of JavaScript

JavaScript type judgment

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.