How to Use Text Processing with Strings

Examples

String conversion

It's possible to use String as a more reliable toString() alternative, as it works when used on null and undefined. For example:

const nullVar = null;
nullVar.toString(); // TypeError: nullVar is null
String(nullVar); // "null"

const undefinedVar = undefined;
undefinedVar.toString(); // TypeError: undefinedVar is undefined
String(undefinedVar); // "undefined"