How to Use Text Processing with Strings

A String is simply a sequence of characters. There are different ways to create Strings – either as a string literal or as a String object using the String() constructor. Strings can be compared to an array of characters and are often accessed similarly. Understanding them is crucial as they play a significant role in input and manipulation within coding.

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"