- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript String trim
JavaScript Strings
JavaScript String trim
trimremoves whitespace from both ends of a string.
Text typed by a person very often has stray spaces.
Trimming before checking or saving avoids a whole class of bugs.
Example
Example
javascript
const entered = " Ada ";
console.log(entered.trim());
console.log(entered.trim().length);The output is Ada then 3.
Trimming and Padding
trim removes whitespace from both ends.
