let student = {
name:'周杰伦',
age:10,
remark: {
grade:'三年',
class:'2班'
}
}
student.height.a
//Uncaught TypeError: Cannot read properties of undefined (reading 'a')
1.prop in obj
'name' in student //true
'height' in student //false
if('height' in student) student.height.a
2.obj.hasOwnProperty(prop)
a.hasOwnProperty('name') //true
a.hasOwnProperty('height') //false
if(a.hasOwnProperty('height')) student.height.a
3.if(obj.prop)
if(student.name) //true
if(student.height) //false
if(student.height) student.height.a
4.推荐写法:obj.prop?
student.height?.a