Skip to content

【10.1练习】 #640

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);

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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