zoukankan      html  css  js  c++  java
  • 运算符 typeof 和 instanceof

    运算符 typeof 和 instanceof

    typeof

    1. 识别所有值类型

    2. 识别函数

    3. 判断是否是引用类型(但是不能区分是那种引用类型)

    (typeof "abc123"); // string
    (typeof 123); // number
    (typeof a); // undefined
    (typeof true); // boolean
    (typeof Symbol('fei')); // symbol
    (typeof function fei() {}); // function
    
    
    (typeof null); // object  *****************************
    (typeof []); // object
    (typeof {}); // object

    instanceof

    ([] instanceof Array) ? "ok" : "no"; // ok
    ([] instanceof Object) ? "ok" : "no"; // ok
    ({} instanceof Object) ? "ok" : "no"; // ok
    
    (null instanceof Object) ? "ok" : "no"; // no   *****************************
  • 相关阅读:
    Linux基础
    杂谈
    MySQL基础
    Effective Java-第4章
    Effective Java-第三章
    Effective Java-第二章
    mybatis
    mapper.xml文件
    Mybatis
    mybatis-config.xml文件详解
  • 原文地址:https://www.cnblogs.com/dafei4/p/14327158.html
Copyright © 2011-2022 走看看