• javascript变量类型


    javascript变量类型

    变量类型分类:(按typeof和instanceof返回值区分)

    基本类型:
    undefined,number,booleanstring,object,function
    
    对象类型:
    基本类型衍生发展而来,可通过instanceoof判断。
    typeof Null                 //undefined
    Null instanceof undefined   //ReferenceError: Null is not defined
    typeof []
    typeof {}
    
    Number与基础类型number是映射关系:
    var a=new Number(123);
    console.log(a.valueOf()===123);     //true
    var b=new String(123);
    console.log(b.valueOf()===123);     //false
    console.log(b.valueOf()==='123');   //true
    
    obj.valueOf()返回的是该对象的原始值。

    直接量和引用类型(执行速度:直接量>引用类型)

    值类型(直接量):
    ‘’,1,Null,undefined
    
    对象直接量:
    {name:'zeng',age:27};
    ['1','2']
    
    函数直接量://表达式不是语句
    var b=function(a,b){return a+b};    //运行 b();
    function(a,b){return a+b;}()    //函数关键字语句
    (function(a,b){return a+b;})()  //强制把function当块执行
    
    引用类型:
    var c = [1,2,3];
    var d = c;
    d[0] = 4;
    console.log(c); //[4,2,3];
    
    例1:
    var a = {"x": 1};
    var b = a;
    console.log(b.x);
    a = {"x":2};
    console.log(b.x);
    a[x] = 3;
    console.log(b.x)
    a.x = 4;
    console.log(b.x); 
    
    (对象直接量/函数直接量)重新赋值产生新的作用域,值类型除外;
    a.x==a{x};
    a{x}!=a.x;
    a.x==a['x'];
    
  • 相关阅读:
    Vue学习-Day1
    Shell脚本学习
    Linux基础
    C# int.Parse()、int.TryParse()与Convert.ToInt32()的区别
    windows下跑python flask,环境配置
    linq性能剖析
    servicestack操作redis
    程序员福利各大平台免费接口非常适用
    ASP.NET下跨应用共享Session和使用Redis进行Session托管简介
    Web Farm和Web Garden的区别
  • 原文地址:https://www.cnblogs.com/eclipsecn/p/3357704.html
Copyright © 2020-2023  润新知