Home / Javascript Tips Generated By ChatGPT / Trimming Whitespace from Strings in Javascript Remove leading and trailing whitespace from a string. Source Code let text = " Hello world! "; console.log(text.trim()); // "Hello world!"