Skip to content
HangoverHangover
首页
项目收藏
留言板
github icon
  • 代码片段

      • 获取变量类型
        • 华氏度和摄氏度
          • 动态引入js
            • 判断类型

          获取变量类型

          author iconHangovercalendar icon2022年4月14日category icon
          • 变量
          tag icon
          • 变量
          • 类型
          timer icon小于 1 分钟

          获取一个变量的类型

          const trueTypeOf = (obj) => Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
          
          trueTypeOf('');     // string
          trueTypeOf(0);      // number
          trueTypeOf();       // undefined
          trueTypeOf(null);   // null
          trueTypeOf({});     // object
          trueTypeOf([]);     // array
          trueTypeOf(0);      // number
          trueTypeOf(() => {});  // function
          
          1
          2
          3
          4
          5
          6
          7
          8
          9
          10
          下一页
          华氏度和摄氏度
          鸟无声兮山寂寂,夜正长兮风淅淅。 ──李华《吊古战场文》
          Copyright © 2023 Hangover