zoukankan      html  css  js  c++  java
  • [JS]数据类型检测

    一、JS中的数据类型
    5种基本数据类型:Number、String、Boolean、Null、Undefined
    1种复杂数据类型:Object(Array、Function、Reg、Date...)

    1.typeof
    语法:
    1. typeof num;
    结果:
    Number/String/Boolean/Undefined/Function正常、null/Array/Reg/Date-->Object

    2.instanceof
    语法:
    1. num instanceof Number;//true or false
    结果:
    Number/String/Boolean都为false,因为非构造函数创建,使用new Number创建则为true
    1. undefined instanceof Object;//true
    2. null instanceof Object;//true

    3.constructor
    语法:
    1. num.constructor==Number;
    结果:
    都为true,但此属性可被修改

    4.Object.prototype.toString.call
    语法:
    1. Object.prototype.toString.call(num)=="[object Number]";

    5.jquery中$.type
    语法:
    1. $.type(num)//number
    结果:同上

    总结5种方法:
     

    附件列表

    • 相关阅读:
      MySQL >>> 存储引擎
      MySQL >>> 基本操作语句
      MySQL >>> 使用安装
      协程 *单线程实现并发
      进程池 & 线程池
      线程 *知识点扩充
      进程 & 线程
      DRF单表序列化
      DRF
      接口规范
    • 原文地址:https://www.cnblogs.com/enginex/p/6815792.html
    Copyright © 2011-2022 走看看