函数传参是传递对象指针的副本以及typeof instanceof 区分(私人仓库)

151 阅读1分钟

1、

函数传参是传递对象指针的副本

function test(person) { 
    person.age = 26 person = {
        name: 'yyy',
        age: 30
    }
    return person}const p1 = {
        name: 'yck',
        age: 25
    }
const p2 = test(p1)
console.log(p1) // -> ?
console.log(p2) // -> ?

2、 typeof vs instanceof

typeof对于原始类型来说,除了null都可以显示正确的类型 对于对象类型,除了函数,都只能显示oject。并不准确。

typeof 对于原始类型来说,除了 null 都可以显示正确的类型
typeof 1 // 'number'
typeof '1' // 'string'
typeof undefined // 'undefined'
typeof true // 'boolean'
typeof Symbol() // 'symbol'
typeof 对于对象来说,除了函数都会显示 object,所以说 typeof 并不能准确判断变量到底是什么类型
typeof [] // 'object'
typeof {} // 'object'
typeof console.log // 'function'

3、

4、