In programming, a variable is a container that holds a value or a reference to a value. It can be thought of as a named placeholder or memory location where data can be stored and accessed.
The value stored in a variable can be changed or manipulated during the program execution, making it a powerful programming construct. Variables are used to store different types of data such as numbers, strings, objects, and more, and they are a fundamental concept in all programming languages.
<!DOCTYPE html>
<html>
<head>
<script src="main.js"></script>
</head>
<body>
<script>
var x = "Hack The Planet";
var y = 1234;
var z = "<hr>";
document.write(x);
document.write(y);
document.write(z);
document.write("Custom Stuff <br>");
document.write("Something Else <br>");
</script>
</body>
</html>
This HTML code includes an external JavaScript file called "main.js" and defines a script block in the body section. Within the script block, three variables are defined: x, y, and z.
The first variable, x, is a string literal containing the text "Hack The Planet". The second variable, y, is an integer with the value of 1234. The third variable, z, is a string literal containing an HTML horizontal rule element.
The script block then uses the document.write method to output the values of the three variables to the HTML document. It first writes the value of x, then the value of y, and finally the value of z. It then writes the strings "Custom Stuff" and "Something Else" to the document, each on a new line.
No comments:
Post a Comment