- Variable Declaration - creates space in memory for variable
- Variable Initialization - puts a value into space for first time
- Variable Assignment - puts new value into space
- Variable Reference - retrieves value from space
- Example
<script type="text/javascript">
var
name;
// Declaration
name =
"bugs";
// Initialization
document.write("<i> Hello " + name + "
</i> "); // Reference
</script>
- Concatenation -- we can join together several "strings" by using
the "+" symbol.
7. Prompts for User Input
- Use
prompt() function to
get user input
- Two
parameters: prompt("Question to User", "Default text for input");
- Example:
<script
type="text/javascript">
name = prompt("Please enter your
name", "name goes here");
document.write("Hello " + name +
", how are you?");
feeling = prompt("Please enter how
you are feeling", "");
document.write("<p>Try
smiling while you are " + feeling +".</p>");
</script>