• typeof与instanceof


    JavaScript数据类型是非常简洁的,它只定义了6中基本数据类型

    null:空、无。表示不存在,当为对象的属性赋值为null,表示删除该属性
    undefined:未定义。当声明变量却没有赋值时会显示该值。可以为变量赋值为undefined
    number:数值。最原始的数据类型,表达式计算的载体
    string:字符串。最抽象的数据类型,信息传播的载体
    boolean:布尔值。最机械的数据类型,逻辑运算的载体
    object:对象。面向对象的基础
    alert(typeof 1); // 返回字符串"number"
    alert(typeof "1"); // 返回字符串"string"
    alert(typeof true); // 返回字符串"boolean"
    alert(typeof {}); // 返回字符串"object"
    alert(typeof []); // 返回字符串"object "
    alert(typeof function(){}); // 返回字符串"function"
    alert(typeof null); // 返回字符串"object"
    alert(typeof undefined); // 返回字符串"undefined"
    instanceof

    判断实例是否属于此类


    function Person(http://www.my516.com) {

    }
    // console.log(Person instanceof Person) flase 说明instenceof 判断的为实例
    const person = new Person();
    console.log(person instanceof Person) // true instanceof 判断实例
    console.log(person instanceof Object) // true 因为person原型链指向constructor Object
     
    ---------------------

  • 相关阅读:
    Linux如何同步时间/更新时间
    Linux关机/重启/及注销命令
    Linux如何查看别名和取消别名
    Linux查看历史记录
    Linux命令行快捷键有哪些
    win10产品密钥 win10永久激活密钥(可激活win10所有版本 )
    Xshell如何连接
    Xshell6 优化
    逻辑运算符
    可变类型与不可变类型
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11192624.html
Copyright © 2020-2023  润新知