Trimming Strings in JavaScript
ECMAScript 5 has support for String#trim, so next time you’re trimming a String in Node (or in a web browser if you don’t care about IE 8), you can trim it like:
' hello '.trim(); // "hello"
instead of the dated regular expression approach:
return this.replace(/^\s+|\s+$/g, "");
Please (please!) use these when you can. I’ve got a really fun post coming up on ECMAScript 5 in more detail. Stay tuned!