Tutorials - JavaScript - Lesson 6 - Variables
Variables allow JavaScript to store data in the program memory so that
it can use that data to perform a variety of functions later. In the previous
tutorial we saw that a variable was used to generate a "customised"
page for the user:
<script language="javaScript">
var readername=prompt('enter your name', '');
</script>
You can see above that the command
var is used.
This is used to define a variable, it therefore
follows that readername
is the variable as it is next to the
var command.
The next command,
=prompt('enter your name',
'');tells the code what type of
variable readername
is, it could be anyone of the following types:
| Example Value |
Description |
Code Example |
| 12345 |
Number (integer) |
var x =12345; |
| 12.43 |
Number (real) |
var x =12.43; |
| 5.21e4 |
Number (real) (5,2100) |
var x = y * 5.21e4; |
| "this is a string" |
String (in quotes) |
var string ='this is a string'; |
But in this case, the code is told that readername is the input that it
will receive from the prompt command - in other words, a string.
In Tutorial 7, we'll look at functions.
back
|