JavaScript I learn a variable type

Source: Internet
Author: User

This article is NetEase Cloud classroom Jin Xu-liang Teacher's course note, records down, to prepare for forgetting.

Variable Type

There are only 6 kinds: four raw data Types Boolean, number, String, undefine, and other object,function are objects

Typeof,instanceof

See examples directly:

        var NULL ;        Console.info (typeof obj);       // Object        var arr = [];         instanceof Object);   // true        instanceof Array);    // true
wrapper objects for raw data types (Wapper object)    String,number,boolean all correspond to specific packaging objects Data type Conversions    Convert to numeric type with Parseint,parsetfolat
//  the //  the // NaN // 3
JavaScript is Dynamic TypeProgramming language, the same variable, what type of data to grab what kind of variable type
//  Number var value = +//stringvalue = "Qiu"//Objectvalue = [1 , ' both ', 3];
various patterns of the "=" Number:
               = =          Assignment                = = =        , etc.                = = =      Strict judgment such as var x =; var y = "x"//true; // false

undefined vs nullUdefine: Refers to the variable is undefined, there is no valid value (not yet variable, what from the talk value)    Null:nothing, a variable does not refer to any object. Null is an object, type object (with variable, but no reference value)
var NULL ; if NULL {alert (// This sentence will be executed }else  {alert ("Obj!=null");} Alert (typeof//Object

Undefine and null judgments, etc.

varMyVar;//trueConsole.log (typeofMyVar = = = "undefined"); Console.log (MyVar===undefined); varMYVAR2 =NULL; Console.log (typeofMYVAR2);//Object//true;Console.log (MyVar2 = =NULL); Console.log (MyVar2===NULL); //trueConsole.info (MyVar = = myVar2);//undefine = = null; is True//falseConsole.info (MyVar = = = MyVar2);//Undefine = = = NULL; is False

true and False    Undefined, Null,nan, "", 0
    In addition to these values, the other values are true; operator:!! with | |!! Convert the following expression to a Boolean value that returns TRUE or FALSE! " Qiu "True!! Null false | |    var ns = NS | | {} If NS is not defined to return {}, the NS note is returned: define variables must be VAR, otherwise drop pits! If you do not write Var, it will become a global variable .

JavaScript I learn a variable type

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.