JavaScript .trimStart()

Anonymous contributor's avatar
Anonymous contributor
Published Oct 14, 2025
Contribute to Docs

The trimStart() method removes whitespace characters from the beginning of a string. It returns a new string with leading whitespace removed, leaving the original string unchanged. This method is also available as trimLeft(), which is an alias for trimStart().

Whitespace characters include spaces, tabs, line breaks, and other Unicode whitespace characters.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

string.trimStart()

Parameters:

The trimStart() method does not take any parameters.

Return value:

Returns a new string with whitespace removed from the beginning of the original string. The original string remains unchanged.

Example

The following example demonstrates how trimStart() removes leading whitespace:

const greeting = ' Hello, World!';
const trimmedGreeting = greeting.trimStart();
console.log(greeting);
console.log(trimmedGreeting);
console.log(greeting.length);
console.log(trimmedGreeting.length);

The output of this code is:

Hello, World!
Hello, World!
16
13

In this example, trimStart() removes the three leading spaces from the string, reducing its length from 16 to 13 characters.

Codebyte Example

Run the following code to see trimStart() in action:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours