js高级进阶

一、 数据类型

1、分类

  • 基本(值)类型
    • String: 任意字符串
    • Number: 任意数字
    • Boolean: true/false
    • Undefined: undefined
    • Null: null
  • 对象(引用)类型
    • Object: 任意对象
    • Function: 一种特别的对象(可以执行)
    • Array:一种特别的对象(数值下标,内部数据是有序的)
      2、判断
  • typeof:
    • typeof 返回数据类型的字符串表达式
    • 不能判断null和objec
    • 可以判断:undefined、数值、字符串、布尔值 、function
  • instanceof:判断对象的具体类型
  • ===
    • 可以判断:undefined、null
// 基本类型
var a;
console.log(a, typeof a, typeof a === 'undefined', a === undefined); // undefined 'undefined' true true
console.log(undefined === 'undefined') // false
a = 4;
console.log(typeof a === 'number'); // true
a = 'sss';
console.log(typeof a === 'string'); // true
a = true;
console.log(typeof a === 'boolean'); // true
a = null;
console.log(typeof a, a === null); // 'object' true 

// 对象
var obj = {
    b2: [1, 'abc', console.log],
    b3: function () {
        console.log(b3)
    }
}
console.log(obj instanceof Object, b1 instanceof Array); // true false
console.log(obj.b2 instanceof Array, obj.b2 instanceof Object); // true true
console.log(obj.b3 instanceof Function, obj.b3 instanceof Object); // true true
console.log(typeof obj.b2); // ''
console.log(typeof obj.b3 === 'function'); // true
console.log(typeof obj.b2[2] === 'function'); // true
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.Object.definePorperty 2.js的执行机制 js是单线程的 js的事件循环(Event L...
    南蓝NL阅读 7,079评论 0 3
  • 有人说过,很多弯路到最后都成了直路,所有的坑到最后也都成了坦途;所谓的直路和坦途并不是摆在眼前的,都是不断的的...
    老衲法号一眉道人阅读 1,385评论 0 4
  • 第一章: JS简介 从当初简单的语言,变成了现在能够处理复杂计算和交互,拥有闭包、匿名函数, 甚至元编程等...
    LaBaby_阅读 1,706评论 0 6
  • 1、js的数据类型: 分类: 基本类型(5种),引用类型 基本(值)类型 ,保存在栈中: String:...
    Shy啊阅读 296评论 0 3
  • 学习目标: 理解面向对象开发思想 掌握 JavaScript 面向对象开发相关模式 掌握在 JavaScript ...
    金桔柠檬加冰阅读 416评论 0 0