# 概述

# JavaScript的数据类型

  • number:1, 1.2 ……

  • string:hello world

  • boolean:true, false

  • undefined

  • null

  • object: Object, Array, Function

# JavaScript确定值类型的三种方式

# 1. typeof

typeof 123 // "number"
typeof '123' // "string"
typeof false // "boolean"
typeof undefined // "undefined"
function f() {}
typeof f
// "function"
1
2
3
4
5
6
7

# 2. instanceof

var o = {};
var a = [];

o instanceof Array // false
a instanceof Array // true
1
2
3
4
5

# 3. Object.prototype.toString

var o={};
o.toString()
// "[object Object]"
1
2
3