zoukankan      html  css  js  c++  java
  • 检测数据类型的方式

    第一题、检测数据类型的方式
    第一种:
    typeof 方法  console.log(type 内容)
    typeof 可以检测基本类型,但是碰到引用数据类型均返回为object。
    第二种:
    instanceof 方法 console.log(内容 instanceof 数据类型)
    instanceof可以用于引用类型的检测,但对于基本类型是不生效的,另为,不能用于检测null和undefined
    第三种:
    constructor 用法 console.log(内容.constructor===数据类型)
    撇去null和undefined,constructor能用于检测js的基本类型和引用类型,但当对象的原型更改之后,constructor便失效了
    第四种
    Object.prototype.toString.call() 用法 console.log(Object.prototype.toString.call(判断的内容))
    可用于检测js所有数据类型

  • 相关阅读:
    洛谷P2334
    线性基
    6.28 模拟赛解题报告
    左偏树
    哈夫曼树 Huffman
    CSP/NOIP 之前还需要学/复习的东西
    CF718C
    6.13 模拟赛结题报告
    关于模拟退火
    『笔记』网络流
  • 原文地址:https://www.cnblogs.com/bigbang66/p/13550051.html
Copyright © 2011-2022 走看看