0
let obj = {}
obj.name  // this is  undefined  
obj.age  // this is undefined

Now I want to return null, How I define obj, not use proxy ?

My js object has this method:

function xxx (key){
  if(key === 'name') return  null
  if(key === 'age') return 'hello age'
  return undefined
}

do not know property, but when use property not return undefined

Tushar
  • 3,527
  • 9
  • 27
  • 49
hxb
  • 1
  • 1
  • 1
    Could you explain what problem your trying to solve here, eg. you could just have done `let obj = {name:null, age: 'hello age'}` and this would line up with your xxx function. – Keith Mar 06 '23 at 10:53

1 Answers1

0

Specify them as null when creating your object at first. For example:

const obj = {
   name : null,
   age : null
}

If you want to change the default value of Javascript object attributes, check out this post.