String Trim in JavaScript

Level 132 keystrokes

trim() removes the spaces at both ends of " hello " and prints "hello".

JavaScript code

// trim() returns a new string without whitespace (spaces, tabs, newlines) at both ends
// Spaces inside the text are kept; only one side: trimStart() or trimEnd()
1console.log(" hello ".trim());

Output

hello
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • .× 2
  • "× 2
  • (× 2
  • )× 2
  • ;× 1

More JavaScript examples at level 1

← JavaScript typing practice