Skip to content

【10.1练习】 #640

@xugy0926

Description

@xugy0926

用typeof obj ==='object' 判断obj是否是一个object。

事例代码

var obj = {
  name: 'xiaoming'
}
    
function output(obj) {
  if (typeof obj === 'object') {
    console.log(obj.name);
  } else {
    console.log('obj is not a object');
  }
}
    
output(obj);

以上代码有缺陷吗?如果有改如何改进?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions