JS TutorialJavascript-HomeJavascript-IntroductionJavaScript-File-UseJavascript-Output-ExampleJavaScript CommentJavaScript VariableJavaScript OperatorJavaScript ConsoleJavaScript StringJavaScript string splitJavaScript string sliceJavascript trim whitespaceJavaScript string indexOf methodJavaScript string lastIndexOf methodJavaScript DateJavascript conditional statement
Javascript trim whitespace
Javascript trim whitespace function is used to remove whitespace from the string . include starting point and ending point of string
Syntax
trim()
trimLeft()
trimRight()
string.trim() function remove whitespace from both starting and ending point of string
Example

Parameter Details
Parameter | Description |
no | it doesn't take any parameter |
Technical Details
Return value | str.trim() function return original string without whitespace |
Browser Support
Browser | |||||
Version | 4 | 3.5 | 10.5 | 10 | 5 |
trimLeft / trimStart
trimLeft or trimStart function used to remove whitespace from starting point of string
Example

trimRight / trimEnd
trimRight or trimEnd used to remove whitespace from ending point of string
Example

Tips - trimStart is alias of trimLeft
Tips - trimEnd is alias of trimRight
Note - trim function doesn't throw error if no whitespace are available in string i.e starting or ending point of string doesn't have whitespace