Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to Check for a Null or Empty String in JavaScript

let myStr = null;

if (myStr === null || myStr.trim() === "") {
  console.log("This is an empty string!");
} else {
  console.log("This is not an empty string!");
}

/*
This will return:

"This is an empty string!"
*/
Comment

javascript syntax for check null or undefined or empty

if (typeof value !== 'undefined' && value) {
    //deal with value'
};
Comment

Check for a Null or Empty String in JavaScript

let myStr = null;

if (myStr === null || myStr.trim() === "") {
  console.log("This is an empty string!");
} else {
  console.log("This is not an empty string!");
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: bootstap jquery 
Javascript :: how is javascript compiled 
Javascript :: replace object in array with another array with same id javascript 
Javascript :: js know size of screen displayed 
Javascript :: momentjs format date 
Javascript :: how to concatenate strings and variables in javascript 
Javascript :: post jquery 
Javascript :: integer to array javascript 
Javascript :: nodemon watch extensions 
Javascript :: css class list 
Javascript :: pattern validator angular 
Javascript :: javascript ready state 
Javascript :: string normalize javascript 
Javascript :: mongodb mongoose push into nested array 
Javascript :: how to get key from value in javascript 
Javascript :: react chart js 
Javascript :: youtube set speed command 
Javascript :: mongodb find all that dont have property 
Javascript :: element clicked js 
Javascript :: js date in two weeks 
Javascript :: regex usage 
Javascript :: jshint ignore 
Javascript :: javascript file on select 
Javascript :: react 18 
Javascript :: reset form input react 
Javascript :: get value of hidden type field 
Javascript :: jquery import js file 
Javascript :: foreach index 
Javascript :: promise.race polyfill 
Javascript :: create select option using jquery 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =