How to Check If String is empty/undefined/null in JavaScript
To check if a string is empty/undefined/null in JavaScript, you can use the “! operator” that returns true for empty strings, undefined values, null values, and other false values. Example 1 function isEmpty(str) { return !str; } const emptyString = ”; const nullValue = null; const undefinedValue = undefined; const nonEmptyString = ‘Hello, world!’; console.log(isEmpty(emptyString)); console.log(isEmpty(nullValue)); … Read more