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 "
-Function1.png)
Then we have used the trim() function to remove any unwanted spaces from beginning and end.
var y = x.trim()
-Function2.png)
Unwanted spaces are stripped out of it.