You can get JavaScript code output by following ways.
To access an HTML element, JavaScript can use the document.getElementById(id) method. The id attribute defines the HTML element. The innerHTML property defines the HTML content. You can get output by using innerHTML method as following example.
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 2 + 3;
</script>
Output
You can get output by using document.write() method as following example.
<script>
document.write(1 + 3);
</script>
Output
You can use an alert box to display data as following example.
<script>
function test(){
window.alert(4 + 3);
}
</script>
<button onClick="test()">click here to display output in alert box.</button>
Output
For debugging purposes, you can use the console.log() method to display data.
<script>
console.log(2 + 6);
</script>
Output
You can see Output in browser console
