Home JavaScript String Methods trimStart() JavaScript String trimStart() Method Definition String.prototype.trimStart() returns a new string with whitespace removed from the start only. Trailing spaces stay. It never mutates the original string (ES2019).
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax Call string.trimStart. Start with this line.
Call What it does string.trimStart()Primary signature. string.trimStart(...)Call with the arguments your case needs.
Built into JavaScript. Call trimStart(...) on a string (or String instance) — no import required.
Library declarations Parameters This member has no parameters beyond those shown in the signature.
Return Value Return Value Description * New string without leading whitespace
JavaScript Examples 1. Basic trimStart 2. Tabs & newlines 3. vs trim / trimEnd Example 1 — Remove Leading Spaces Drop spaces from the start; keep spaces at the end.
const text = " Hello ";
console.log(JSON.stringify(text.trimStart()));
// "Hello " How It Works Start with padded text. " Hello " has spaces on both sides.Call trimStart(). Only the leading spaces are removed.Trailing stays. The result is "Hello " — two spaces remain at the end.Original unchanged. text is still " Hello ".Example 2 — Tabs & Newlines at the Start Leading tabs and newlines count as whitespace too.
const text = "\t\nCodeToFun ";
console.log(JSON.stringify(text.trimStart()));
// "CodeToFun " How It Works Leading whitespace varies. The string starts with a tab and a newline.trimStart skips them. Both count as whitespace, so they are removed.Content remains. Result starts at "C" → "CodeToFun ".End padding kept. The two trailing spaces are not touched.Example 3 — trimStart vs trim vs trimEnd See which end each method cleans.
const text = " Hi ";
console.log(JSON.stringify(text.trimStart())); // "Hi "
console.log(JSON.stringify(text.trimEnd())); // " Hi"
console.log(JSON.stringify(text.trim())); // "Hi" How It Works trimStart. Cleans the left → "Hi ".trimEnd. Cleans the right → " Hi".trim. Cleans both ends → "Hi".Rule of thumb. Need only the start cleaned? Use trimStart().Compatibility
Browser & Runtime Support String.prototype.trimStart() is part of ES2019 and is Baseline Widely available in modern browsers and current Node.js.
✓ Baseline · ES2019
String.prototype.trimStart() Supported in Chrome 66+, Firefox 61+, Safari 12+, Edge 79+, and Node 10+. Also available as the alias trimLeft().
98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support trimStart() Excellent
Bottom line: Safe for modern web apps and current Node LTS releases. Prefer trimStart() over trimLeft() for clearer, consistent naming.
Frequently Asked Questions What does String.trimStart() do? trimStart() returns a new string with whitespace removed from the beginning only. Trailing whitespace is kept. The original string is not changed.
Is trimLeft the same as trimStart? Yes. trimLeft() is an alias of trimStart() — they are the same function. Prefer trimStart() for consistency with padStart() and trimEnd().
What counts as whitespace? Whitespace includes spaces, tabs, newlines, and other white space characters plus line terminators — the same rules as trim().
How is trimStart different from trim and trimEnd? trim() cleans both ends. trimStart() removes only from the start. trimEnd() removes only from the end.
Does trimStart change the original string? No. Strings are immutable. trimStart() always returns a new string — even when there was nothing to remove.
When should I use trimStart? When you must keep trailing padding or spaces but want to drop leading spaces, tabs, or indentation.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion