Use
to show space in an HTML document. You can create a string with multiple spaces in JavaScript.
let a = `something something`;
var a = 'something' + '         ' + 'something'
JavaScript space character
Simple example code.
<!DOCTYPE html>
<html>
<body>
<script>
var str ='something' + '         ' + 'something'
document.write(str)
</script>
</body>
</html>
Output:
Or
If you write 10 spaces in your text, the browser will remove 9 of them. To add real spaces to your text, you can use the character entity.
var a = 'something' + '         ' + 'something';
document.body.innerHTML = a;
Space in JavaScript console
<script>
var a = 'something' + '\xa0\xa0\xa0\xa0\xa0\xa0\xa0' + 'something';
console.log(a)
</script>
You could compare with “==” instead of “===” and use ‘\xa0’ for comparing
which is the actual character for non-breaking space.
Do comment if you have any doubts or suggestions on this Js topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version