1.Create a Basic JavaScript Variable code Example-1
<!DOCTYPE html> <html> <body> <h2>JavaScript Variables</h2> <p>In this example, x, y, and z are variables.</p> <p id="demo"></p> <script> var x = 5; var y = 6; var z = x + y; document.getElementById("demo").innerHTML = "The value of z is: " + z; </script> </body> </html>
<!DOCTYPE html> <html> <body> <h2>JavaScript Variables</h2> <p id="demo"></p> <script> var price1 = 5; var price2 = 6; var total = price1 + price2; document.getElementById("demo").innerHTML = "The total is: " + total; </script> </body> </html>
<!DOCTYPE html> <html> <body> <h2>JavaScript Variables</h2> <p>Strings are written with quotes.</p> <p>Numbers are written without quotes.</p> <p id="demo"></p> <script> var pi = 3.14; var person = "John Doe"; var answer = 'Yes I am!'; document.getElementById("demo").innerHTML = pi + "<br>" + person + "<br>" + answer; </script> </body> </html>
<!DOCTYPE html> <html> <body> <h2>JavaScript Variables</h2> <p>You can declare many variables in one statement.</p> <p id="demo"></p> <script> var person = "John Doe", carName = "Volvo", price = 200; document.getElementById("demo").innerHTML = carName; </script> </body> </html>
<!DOCTYPE html> <html> <body> <h2>JavaScript $</h2> <p>The dollar sign is treated as a letter in JavaScript names.</p> <p id="demo"></p> <script> var $ = 2; var $myMoney = 5; document.getElementById("demo").innerHTML = $ + $myMoney; </script> </body> </html>