Methods
-
string.prototype.trim()
- The
trim()
method removes whitespace from both ends of a string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.). -
Description
The
trim()
method returns the string stripped of whitespace from both ends.trim()
does not affect the value of the string itself. -
var orig = ' foo '; console.log(orig.trim()); // 'foo' // Another example of .trim() removing whitespace from just one side. var orig = 'foo '; console.log(orig.trim()); // 'foo'
- The
-
String.prototype.toUpperCase()
- The
toUpperCase()
method returns the calling string value converted to uppercase (the value will be converted to a string if it isn't one). -
Description
The
toUpperCase()
method returns the value of the string converted to uppercase. This method does not affect the value of the string itself since JavaScript strings are immutable.
You cannot call this method onnull
orundefined
(viaFunction.prototype.call
, for example) , if you do, aTypeError
will be thrown. -
console.log('alphabet'.toUpperCase()); // 'ALPHABET'
- The
永远渴望,大智若愚(stay hungry, stay foolish)