JavaScript trim() is used to trim the spaces from left and right. In the below example, We have a string " Michael " which will be converted to "Michael" after trim function is applied. See the code snippet:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<script>
var name=" Michael ";
document.write(name.trim());
</script>
</body>
</html>