This section provides descriptions on variables and a tutorial example on how to declare variables with 'var' statements.
What are variables?
Variables are symbolic names that refer to values stored in the memory.
Variable names must be sequences of alphanumeric characters and underscore (_).
But the first character can not be a numeric character. (_5star) is a valid variable name.
But (5star) is not an invalid variable name.
Variable can be used without declaration.
But it is strongly recommended that all variables are declared with "var" statements
in the following syntax formats:
var var_name_1;
var var_name_1 = value_1;
var var_name_1, var_name_2, var_name_3, ...;
var var_name_1 = value_1, var_name_1 = value_1, ...;
If a variable is declared without initial value, it contains the "undefined" value.
Here is a JavaScript tutorial example that shows you how to declare variables with "var" statements:
<html>
<!-- Variables.html
Copyright (c) 2008 by Dr. Herong Yang, http://www.herongyang.com/
-->
<head><title>Variables</title></head>
<body>
<pre>
<script type="text/javascript">
var site_url = "herongyang.com";
var site_rank = 3;
var site_content;
document.write(site_url);
document.write('\n');
document.write(site_rank);
document.write('\n');
document.write(site_content);
document.write('\n');
</script>
</pre>
</body>
</html>