javascript check if undefined or null
if(typeof comment === 'undefined') {
alert('Variable "comment" is undefined.');
} else if(comment === null){
alert('Variable "comment" is null.');
}if( typeof myVar === 'undefined' || myVar === null ){
// myVar is undefined or null
}// simple check do the job
if (myVar) {
// comes here either myVar is not null,
// or myVar is not undefined,
// or myVar is not '' (empty string).
}
Also in JavaScript:
- javascript array find highest value of array of objects by key
- get current week number javascript
- javascript get values from object
- javascript confirm yes no
- click listener on by class name in javascript
- javascript detect click outside element
- how to check if enter is pressed javascript
- js is letter
- clone javascript object
- two button in one row react native
- webpack Module not found: Error: Can't resolve '../
- how to make a translator in python
- javascript leave page warning
- angular formarray remove all
- puppeteer set header
- get and set es6
- javascript get random floating number
- reference error $ is not defined jquery
- how to export fs.readFile
- mask date of birth/ dob in javascript
- node js get file name without extension
- colors in node js console
- swap variables using temp javascript
- drupal 8 render node programmatically