isEmpty (JavaScript)
Checks whether a string is empty.
Defined in
String (Standard - JavaScript)Syntax
isEmpty() : boolean
Return value | Description |
---|---|
boolean |
True if the string is empty; otherwise false. |
Usage
An empty string has a length of 0.For
an empty string, s==""
is true, but s==null
is
false.
Examples
(1) This example returns the content ofcities
.var cities = "Paris";
// Should not be empty
if (cities.isEmpty()) {
return "Empty";
} else {
return "'" + cities + "'";
}
(2) This example returns
Empty
.var cities = "";
// Should be empty
if (cities.isEmpty()) {
return "Empty";
} else {
return "'" + cities + "'";
}
(3) This example returns the content of
cities
.var cities = " ";
// Should not be empty
if (cities.isEmpty()) {
return "Empty";
} else {
return "'" + cities + "'";
}