You can just check if the variable has a
truthy
value or not. That means
if( value ) {
}
will evaluate to true if value is not:
- null
- undefined
- NaN
- empty string ("")
- 0
- false
TO be more safe , we can use as below which takes care of not declared variable as well
if (typeof value != 'undefined' && value) {
//deal with value'
};
0 comments :
Post a Comment