JS judge undefined type, undefined,null the difference of detailed analysis

Source: Internet
Author: User

  This article is mainly on the JS to determine the type of undefined, undefined,null,nan the difference between the detailed analysis of the introduction, the need for friends can come to the reference, I hope to help you.

JS judge undefined type   use ShowModalDialog to open the page today and return the value. When the open page clicks the Close button or the direct point of the browser on the close then the return value is undefined so the smart Judge      var revalue=window.showmodaldialog ("", "", "");     if (revalue== undefined) {  alert ("undefined"); &nbsp}   found not to be judged, finally looked up the data to use the TypeOf   method: if (t Ypeof (revalue) = = "undefined") {      alert ("Undefined"); }    typeof returns a string of six possible: " Number "," string "," Boolean "," Object "," function "," undefined "    JS Undefined,null,nan difference   1. Type analysis: The data type in JS has 5 kinds of undefined,boolean,number,string,object, the first 4 is the original type, and the 5th type is reference. var A1; var a2 = true; var a3 = 1; var a4 = "Hello"; var A5 = new Object (); var a6 = null; var a7 = NaN; var a8 = undefined; Alert (typeof a);    //display "undefined" alert (typeof A1); Displays "Undefined" alert (typeof A2); Displays "boolean" Alert (typeof A3); Displays "Number" alert (typeof A4); Displays "string" alert (typeof A5); Displays "Object" alert (typeof A6); Displays "Object" alert (typeof A7); Displays "Number" alert (typeof A8); Show"Undefined"   from the above code you can see that undefined values and definitions are not assigned to Undefined,null is a special Object,nan is a special number.   2. Comparison operation var A1;        //A1 value is undefined var a2 = null; var a3 = NaN; alert (a1 = = A2); Displays "True" alert (A1!= A2); Displays "false" alert (a1 = = A3); Displays "false" alert (A1!= A3); Displays "True" alert (a2 = = A3); Displays "false" alert (A2!= A3); Displays "True" alert (a3 = = A3); Displays "false" alert (A3!= A3); Show "true"   from the above code it can be concluded that (1) undefined is equal to null and (2) Nan is unequal to any value and not equal to itself.   JavaScript undefined properties   definitions and usages undefined properties are used to store JavaScript undefined values.   Syntax undefined   Description You cannot use the for/in loop to enumerate undefined properties, and you cannot delete it with the delete operator. Undefined is not a constant, you can set it to a different value. Undefined is also returned when an attempt is to read an object property that does not exist.   Hint and comment hint: You can only use the = = operation to test whether a value is undefined, because the = = operator considers the undefined value equivalent to null. Note: null means no value, and undefined represents an undeclared variable, or a variable that is declared but not assigned, or an object property that does not exist.   example In this case, we will detect one of the two variables not defined: <script type= "Text/javascript" > var t1= "" Var T2 if (t1===undefined) {Document.wri Te ("T1 is undefined")} if (t2===undefined{document.write ("T2 is undefined")} </script>   output: T2 is undefined     

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.