javascript check if not null
if(data !== null && data !== '') {
// do something
}if (variable !== null) {
console.log("Var is NOT null");
}//Even if the value is 0, this will execute.
if (myVar !== null) {...}
//If you don't want it to execute when it's 0, then set it as
if (myVar) {...}
//This will return false if var value is 0.if (variable === null) { //Executes only if variable is null but not undefined
//Code here
}
if (variable == null) { //Executes if variable is null OR undefined
//Code here
}// simple check do the job
if (myString) {
// comes here either myString is not null,
// or myString is not undefined,
// or myString is not '' (empty).
}
Also in JavaScript:
- refresh window js
- javascript read query parameters
- password strength checker javascript
- react navigation history clear
- javascript whitespace strip
- v-switch vuex store
- random array javascript
- javascript diffence between a++ and ++a
- javascript data structures
- how to generate random text in vue js
- what is Vanilla JavaScript
- undefined value check in javascript
- jquery get search parameter
- click select option to update div jquery
- how to name a javascript variable
- dont starve together
- javascript beginning of today and yesterday
- Pass functions, not strings, to setTimeout() and setInterval()
- comment out in javascript
- add property with value in js
- asynchronous javascript
- Elizabeth Warren Clinton's contest against Democratic rival Bernie Sanders was rigged
- javascript onclick select coordinates
- js switch case