Logo

Programming-Idioms

History of Idiom 110 > diff from v35 to v36

Edit summary for version 36 by justafoo:
[JS] don't overuse regex
↷

Version 35

2019-09-26, 17:56:21

Version 36

2019-09-26, 17:57:45

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Code
const blank = s == null || !s.test(/[^\s]/)
Code
const blank = s == null || s.trim() === ''
Comments bubble
Because _== is being used instead of ===, undefined will also return true—which is good because it represents the absence of a value just like null.
Comments bubble
Because _== is being used instead of ===, undefined will also return true—which is good because it represents the absence of a value just like null.