JavaScript String trimStart() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
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.

JavaScript
string.trimStart()
CallWhat 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
JavaScript
string.trimStart()

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*New string without leading whitespace

JavaScript Examples

Example 1 — Remove Leading Spaces

Drop spaces from the start; keep spaces at the end.

JavaScript
const text = "  Hello  ";

console.log(JSON.stringify(text.trimStart()));
// "Hello  "
Try It Yourself

How It Works

  1. Start with padded text. " Hello " has spaces on both sides.
  2. Call trimStart(). Only the leading spaces are removed.
  3. Trailing stays. The result is "Hello " — two spaces remain at the end.
  4. Original unchanged. text is still " Hello ".

Example 2 — Tabs & Newlines at the Start

Leading tabs and newlines count as whitespace too.

JavaScript
const text = "\t\nCodeToFun  ";

console.log(JSON.stringify(text.trimStart()));
// "CodeToFun  "
Try It Yourself

How It Works

  1. Leading whitespace varies. The string starts with a tab and a newline.
  2. trimStart skips them. Both count as whitespace, so they are removed.
  3. Content remains. Result starts at "C" → "CodeToFun ".
  4. End padding kept. The two trailing spaces are not touched.

Example 3 — trimStart vs trim vs trimEnd

See which end each method cleans.

JavaScript
const text = "  Hi  ";

console.log(JSON.stringify(text.trimStart())); // "Hi  "
console.log(JSON.stringify(text.trimEnd()));   // "  Hi"
console.log(JSON.stringify(text.trim()));      // "Hi"
Try It Yourself

How It Works

  1. trimStart. Cleans the left → "Hi ".
  2. trimEnd. Cleans the right → " Hi".
  3. trim. Cleans both ends → "Hi".
  4. Rule of thumb. Need only the start cleaned? Use trimStart().

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

trimStart() returns a new string with whitespace removed from the beginning only. Trailing whitespace is kept. The original string is not changed.
Yes. trimLeft() is an alias of trimStart() — they are the same function. Prefer trimStart() for consistency with padStart() and trimEnd().
Whitespace includes spaces, tabs, newlines, and other white space characters plus line terminators — the same rules as trim().
trim() cleans both ends. trimStart() removes only from the start. trimEnd() removes only from the end.
No. Strings are immutable. trimStart() always returns a new string — even when there was nothing to remove.
When you must keep trailing padding or spaces but want to drop leading spaces, tabs, or indentation.

Next: trimEnd()

Learn how to remove whitespace from the end of a string only.

trimEnd() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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