javascript variables in html code example
Example 1: html use js variable as text
<h1>"My number: " <span id="myText"></span></h1>
<script>
(() => {
var number = "123";
document.getElementById("myText").innerHTML = number;
})();
</script>
Example 2: variables in html
<var>This text will be italicized</var>
Example 3: js variable html
<div onload="document.innerHTML(name + ' is ' + age)">
Example 4: how to create variables using javascript
var myVar;
var number = 1;
var string = " hello world " ;
var boolean = true ;
myVar = function(){
};
Example 5: html define javascript variable
<script>
var Number = 5;
var String = "Hi!";
var boolen1 = true;
var boolen2 = false;
var array = [11, "Hi!", true];
var object = {age:11, speach:"Hi!", likes_Bananas:true};
</script>