I have the following statement which I'd like to have return any of these values if they are set, otherwise just return null.
var token = request.body.token || request.query.token || request.headers['x-access-token'];
However, whenever one of these is not set it throws a TypeError exception (cannot read property of undefined).
I thought something like this might be the solution but it's throwing the same exception:
var token = (typeof request.body.token === 'undefined') ? null : request.body.token || (typeof request.query.token === 'undefined') ? null : request.query.token || (typeof request.headers['x-access-token'] === 'undefined') ? null : request.headers['x-access-token'];
Can someone suggest a better way of achieving this?