String.prototype.isEmpty = function() {// This doesn't work the same way as the isEmpty function used// in the first example, it will return true for strings containing only whitespacereturn (this.length === 0 || !this.trim());};console.log("example".isEmpty());
function tell(){var pass = document.getElementById('pasword').value;var plen = pass.length;
// Now you can check if your string is empty as likeif(plen==0){alert('empty');}else{alert('you entered something');}}
<input type='text' id='pasword' />
function isBlank(pString) {if (!pString) {return true;}// Checks for a non-white space character// which I think [citation needed] is faster// than removing all the whitespace and checking// against an empty stringreturn !/[^\s]+/.test(pString);}
var y = "\0"; // an empty string, but has a null character(y === "") // false, testing against an empty string does not work(y.length === 0) // false(y) // true, this is also not expected(y.match(/^[\s]*$/)) // false, again not wanted
function is_empty(x){return ( //don't put newline after return(typeof x == 'undefined')||(x == null)||(x == false) //same as: !x||(x.length == 0)||(x == 0) // note this line, you might not need this.||(x == "")||(x.replace(/\s/g,"") == "")||(!/[^\s]/.test(x))||(/^\s*$/.test(x)));}
var x =" ";var patt = /^\s*$/g;isBlank = patt.test(x);alert(isBlank); // Is it blank or not??x = x.replace(/\s*/g, ""); // Another way of replacing blanks with ""if (x===""){alert("ya it is blank")}
let undefinedStr;if (!undefinedStr) {console.log("String is undefined");}
let emptyStr = "";if (!emptyStr) {console.log("String is empty");}
let nullStr = null;if (!nullStr) {console.log("String is null");}
function isEmpty(strValue){// Test whether strValue is emptyif (!strValue || strValue.trim() === "" ||(strValue.trim()).length === 0) {// Do something}}