The trim() Function is used to remove any unwanted character from the String with Space by default.
<html> <body> <script> var x = " Hello " var y = x.trim() document.write(y) </script> </body> </html>
In the above code, we have declared a String Hello with leading and trailing spaces.
var x = " Hello "
Then we have used the trim() function to remove any unwanted spaces from beginning and end.
var y = x.trim()
Unwanted spaces are stripped out of it.