JavaScript Glossary - Lesson #27

JavaScript String .trim() Method

This method removes whitespaces from the start and end of the calling string. It removes spaces, tabs, no break spaces etc. It returns a new string stripped of whitespaces from both sides of the array.

""   hello world   "".trim()
// hello world

Note the method is also case sensitive

const trimmedSent = oldString.trim()

A new string object without whitespace at both ends. It doesn’t change the calling string.

Want to improve your coding and design skills?

I'm continually researching the best practices and tools for coding.
Join 50,000+ developers looking to make cool stuff.

We value your privacy. 1-click unsubscribe.

Chris Sev

Chris Sev

Chris Sev is the co-founder of Better Dev. Coding better every day. Previously he created which was acquired.


What did you think of the article? Let us know!
(these comments are powered by GitHub issues and use 0 trackers)