January 2020
Intermediate to advanced
548 pages
13h 36m
English
Detecting strings is pleasantly simple. The typeof operator is all we need:
typeof 'hello'; // => "string"
In order to check for the length of a given String, we can simply use the length property:
'hello'.length; // => 5
If we need to check whether a String has a length greater than 0, we can either explicitly do so via length or rely on the falsiness of a 0 length, or even rely on the falsiness of the empty string itself:
const string = '';Boolean(string); // => falseBoolean(string.length); // => falseBoolean(string.length > 0); // => false// Since an empty String is falsy we can just check `string` directly:if (string) { }// Or we can be more explicit:if (string.length) { }// Or we can be maximally explicit:if (string.length ...Read now
Unlock full access