I asked the same question of the lodash maintainers a while back and they replied by mentioning the !=
operator can be used here:
if(newVal != null) {
// newVal is defined
}
This uses JavaScript's type coercion to check the value for undefined
or null
.
If you are using JSHint to lint your code, add the following comment blocks to tell it that you know what you are doing - most of the time !=
is considered bad.
/* jshint -W116 */
if(newVal != null) {
/* jshint +W116 */
// newVal is defined
}