In the example below, we create a variable called userName and assign the value "John1234" to it.
Then we "output" the value inside an HTML paragraph with id="test"
Then we "output" the value inside an HTML paragraph with id="test"
<!DOCTYPE html>
<html>
<body>
<div id="test"></div>
<script>
var userName = "John1234";
document.getElementById("test").innerHTML = userName;
</script>
</body>
</html>
Most Helpful This Week
ES6 method of declaration multiple variables in one line
How to define Global Variable in JavaScript?
How to declare multiple variables in one statement in Javascript?
How to check a variable is undefined in JavaScript?
How to check if an element or HTML tag exists using JavaScript?
Highlight and get the details of table row on click using JavaScript