The pure undefined method in JavaScript, javascriptundefined

Source: Internet
Author: User

The pure undefined method in JavaScript, javascriptundefined

1. Why get undefined?

Because undefined is not a reserved word in javascript, it can be assigned as a variable. If undefined is used to detect a variable in the future, the value of undefined is inaccurate;

Example:

Var undefined = 10; function sum (a, B) {if (a === undefined | B === undefined) {console. log ("Incorrect Parameter");} 18101130357 return a + B ;}

Sum ()-> If the parameter is correct, the console outputs "parameter error ";

At this time, in order to be compatible with all browsers, we need to obtain a pure undefinde

2. How to obtain pure undefined?

1) void (0 ):

The ECMAScript 262 specification is described as follows:

The void OperatorThe production UnaryExpression : void UnaryExpression is evaluated as follows:Let expr be the result of evaluating UnaryExpression.Call GetValue(expr).Return undefined.

In short, remember that no matter what the expression after void is, the void operator will return undefined.

2) input a parameter that is assigned a value.

[Case]

Function (_ undefined) {// The value of _ undefined is not assigned to the function body. The value of _ undefined is undefined. You can use _ undefined in this function}

3) unassigned variables

For example, var num // The truth is the same as 2 ).

Do not get bored with familiar things, make progress every day; Do not fear unfamiliar things, learn a little every day;

PS: js determines the undefined type

If (reValue = undefined) {alert ("undefined");} found that the judgment could not be found, and finally found the information to use the typeof method: if (typeof (reValue) = "undefined") {alert ("undefined ");}

Typeof returns a string, which may be "number", "string", "boolean", "object", "function", or "undefined"

Articles you may be interested in:
  • Detailed analysis of differences between js and undefined types, undefined and null
  • Js checks whether the parameter (String, Array, Object) is undefined or the value is null.
  • Js judges the undefined variable type using typeof
  • Summary of differences between null, NaN, and undefined in Javascript
  • Js null, undefined, string Summary
  • Differences between undefined and null in javascript
  • JavaScript code used to determine undefined
  • Difference between JavaScript null and undefined
  • Analysis of null and undefined in JavaScript
  • JavaScript Undefined, difference between the Null type and the NaN Value
  • Differences between undefined and "undefined" In JScript
  • Distinguish undefined, null, "", 0, and false in JS

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.