The number data type, consist of any number with or without decimal places.
var number1 = 12.35;
var number2 = 123;
var bigNumber = 123e4; /*1230000*/
var smallNumber = 123e-4; //0.0123
The string type is any type of text. Text must be surrounded with
" " or
var name = "This is my name", and you want to display quotes between the text, you should write:
var name = " 'This is my name ' ".
var firstName = "Vasilis"; /*Vasilis*/
var lastName = 'Palilis'; //Palilis
var message = "It's alright"; //It's alright
The Boolean type contains only two values,
false. Booleans are commonly used on conditional as we will see later on the course.
var p = true;
var q = false;
var myBool = true; /*Boolean type*/
var myString = "true"; //String type
A variable type can change
If you do this:
var myVar = "true";
and then this:
myVar = true;
the type of the variable is immediately changed from "
string" to "
Try this on your console. Go and type
typeof (true). What do you see?
- Open your editor, create a new file and save it as
exersice05.3.01.htmlin the folder "yourNameWEB2JS".
- Copy the below code and paste it into the new file.