Mots clés : javascriptnullis-emptyjavascript
92
if (strValue) { //do something }
if (strValue === "") { //... }
82
function isEmpty(str) { return (!str || str.length === 0 ); }
function isBlank(str) { return (!str || /^\s*$/.test(str)); }
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 whitespace return (this.length === 0 || !this.trim()); }; console.log("example".isEmpty());
76
if (!!str) { // Some code here }
if (Boolean(str)) { // Code here }
68
if (!str.length) { ...
52
if(str.replace(/\s/g,"") == ""){ }