Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Brandon Heng
Brandon Heng
Courses Plus Student 687 Points

What is trailing white-space? Can anyone help explain me about this also give me some example?

I do not know What is trailing white-space.

1 Answer

Samuel Ferree
Samuel Ferree
31,722 Points

Trailing white space is characters at the end of a string, that can't be seen when printed like spaces or tabs. consider the two strings

"Dave" and "Dave "

Both would look the same to a user, if they were just printed to the screen.

but they might cause problems...

len("Dave") // 4
len("Dave    ") // 8

"Dave" == "Dave    " // false
"Dave" != "Dave    " // true

It happens usually because of user input mistakes.

I might type my name, hit the space key on accident, then press enter, since I can't see the space key at the end of my input. But because it causes problems it needs to be removed from the end of strings. This is why user input is often "trimmed" which removes all trailing whitespace.