[solved] Use javascript property if it exists, otherwise use this other one


#1

When users register on my site their have their user.profile.name set, every time with no exceptions. I want to allow them to set a nickname.

So if the user has that nickname set, use that, otherwise fallback to the safe user.profile.name. I’m not sure how this is done in Javascript.

var itemRecord = _.extend(item, {
  userId: user._id, 
  owner: user.profile.ingameName || user.profile.name, // Obviously this is wrong.
  createdAt: new Date()
});

Any suggestions?


#2

Huh that worked. I just wrote pseudo code as an example. Oh well.