基本数据类型
Number
Number.prototype.toString === new Number(123).__proto__.toString
const num = 123
console.log(num.toString())
String
String.prototype.toString === new String('hello').__proto__.toString
const str = 'hello'
console.log(str.toString())
Boolean
Boolean.prototype.toString === new Boolean('hello').__proto__.toString
const boo= true
const boo1 = false
console.log(boo.toString())
console.log(boo1.toString())
null和undefined
null
和undefined
这两种数据类型没有包装类,所以无法调用包装类上的方法
null.toString()
undefined.toString()
引用数据类型
Object
Object.prototype.toString === new Object({a: 1}).__proto__.toString
Object.toString() => "function Object() { [native code] }"
let obj = {
a: 1
}
obj.toString()
Array
Array.prototype.toString === new Array([1, 2]).__proto__.toString
let arr = [1,2]
arr.toString()
Function
Function.prototype.toString === new Function(function(){}).__proto__.toString
let func = function(){}
func.toString()