1. typeof

  • typeof 返回类型有7种:string number boolean undefined Function Object Symbol(es6)
  • typeof 不能判断数组类型,只能判断数据类型
  • typeof 返回的值为字符串,
    1. alert(typeof a == "string") --> true
    2. alert(typeof a == String) --> false
    1. function test(){}
    2. console.log(typeof 1); // number
    3. console.log(typeof test); // function
    4. console.log(typeof "yunxi"); // string
    5. console.log(typeof undefined); // undefined

    2.instanceof

    返回boolean类型值
    1. console.log([] instanceof Array); // true
    2. console.log(/\d+/g instanceof Array); // false

    3.constructor

    返回boolean类型值
    1. console.log(arr.constructor == Array); // true

    4.Array.isArray(数组)

    返回boolean类型值
    1. Array.isArray(state.car) //true