You could also do if(userOne["email"]) but I would not recommend to check like this userOne.email !== undefined because what if the object in general does not exist?
means:
When userOne does not exist e.g. you forget to pass parameter in a function call, then (undefined).email !== undefined will evaluate not into false or true
A fix for that though would be to check if the object exist and if not, assign an empty object to it. options = options ?? {} if (options.switch !== undefined) can now resolve in true or false.
You could also do
if(userOne["email"])
but I would not recommend to check like thisuserOne.email !== undefined
because what if the object in general does not exist?means:
When userOne does not exist e.g. you forget to pass parameter in a function call, then
(undefined).email !== undefined
will evaluate not into false or true=> skip if condition
A fix for that though would be to check if the object exist and if not, assign an empty object to it.
options = options ?? {}
if (options.switch !== undefined)
can now resolve in true or false.Yeah that's why I mentioned the undefined check to be the least favorite one of all.
It get's messy and very prone to cause headaches later on.
As suggested in another comment optional chaining will work just fine here.