javascript学习1

JavaScript 数据类型

String Number Boolean Undefined Object Array null

let str = 'string'
console.log(typeof str);
//string
let number = 123
console.log(typeof number);
//number
let boolean = true
console.log(typeof boolean);
//boolean
let undefin = undefined
console.log(typeof undefin);
//undefined
let obj = {xxx:'sss'}
console.log(typeof obj)
//object
let array =  [1,2,2]
console.log(typeof array)
//object
let nu = null;
console.log(typeof nu);
//object

除了前四个基本数据类型 其他数据类型 typeof 输出都是object (数组也是一个对象)
所以判断是否为数组最好使用 instanceof

console.log(array instanceof Array)
//true

但是

console.log(Number instanceof Number)
//false

你可能感兴趣的:(javascript学习1)