How to display a JavaScript variable value in an HTML page?

To display a JavaScript variable value in an HTML page, add an HTML element to your page, then set its textContent to your variable.

First, add an element like so:

<div id="js-variable"></div>

Then use this JavaScript to display your variable:

document.getElementById('js-variable').textContent = yourVariable;

Don't forget to set the value, that you want to display to yourVariable before doing that.