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