Js object-oriented learning note 6 (variable)

Source: Internet
Author: User

Js object-oriented learning note 6 (variable)
[1. boolean corresponding to the value]

False Boolean value false object null number NaN (not a number) number 0 Initial Value undefined empty string "" true string "0" or other non-above six values



[2. Differences between null and undefined]
Null is actually an empty object or an array undefined. It is a declared or undeclared variable, but the initial value of the variable is not assigned. Therefore, no undefined object has no initial value without var declaration. the variable values are all undefined.



[3. Types of detection variables]
var a; typeof(a) ; //undefined var a = "0"; typeof(a) ; //string var a = 0; typeof(a) ; //number var a = null,     b = new Array(1,2,3); typeof(a) ; //object typeof(b) ; //object var a= function(){    alert(12); } typeof(a) ; //function



[Note:] all variables must be declared using var before they are used.

Check whether the variable has if (typeof (somevar )! = "Undefined") {// exist coding here ...}



[Maximum value in 4. js]
Var maxnumber = Infinity; // note that Infinity is a built-in constant var minnumber =-Infinity; // the smallest negative js number.

[5. Scope of variables]

 

Var a = 123; function f () {alert (a); // undefined var a = 2; alert (a); // 2}; f (); // For The First Time: Variable scan is not assigned a value // for the second time: sequence assignment and execution


 

 

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.