Lesson 102 – Data Types
Some other data types are:
- Boolean – this is a data type that describes data as being either true or false.
The function – typeof() – will tell you what the data type is of whatever you put inside the brackets. For example,
will return – “number”. And
will return – “string”. And
will return – “boolean”.
A prompt is very similar to an alert but a prompt allows a user to input something like a piece of text. This is an example of a prompt:
prompt("What is your name?");
This is an example of a variable –
var myName = "Shane";
The word “var” is a keyword which tells us that we are creating a new variable or data container.
The name of the data container or variable in this case is – myName.
The variable called “myName” is set to be equal to the text string “Shane”.
The word “var” is only used when constructing a new data container. Once the container has been constructed you can change what is held within that container by simply referring to the name which you have already assigned to that container.
Using the above example. the variable of “myName” has been created and has been assigned the name “Shane”. If I want to change the meaning of the variable “myName”, I can do so as follows:
myName = "Joe";
I don’t have to use –
var myName = "Joe";