Variables in the JavaScript | standard ES5
last updated: 1 Augusta 2020
In the JavaScript variables can contain :
• text
• integer number, fractional number
• flag (true, false)
• date and time (year month number hours minutes seconds)
Example
Html
<script>
// number
var Age = 45;
// text
var Name = "Magician" ;
// flag
var Sleep = true;
// date and time
// January 11, 2019 15:10:25
var Birthday = new Date(2019, 0, 11, 15, 10, 25);
</script>
Syntax (create a variable)
JavaScript
var Name = meaning;
var create a variable
var it is an abbreviation of the word variable (translated from English variable )
Text in the JavaScript
Html
Example
<script>
// option 1
var myText1 = "Hello" ;
// option 2
var myText2 = String("World" );
// option 3
var myText3 = new String("Home" );
</script>
To work with text (Find text, text length, add text, etc.) class is used
String
Number in the JavaScript
In the JavaScript a number can be an integer or a fractional (floating-point) number.
Html
Example
<script>
// Option 1. Integer
var value1 = 45;
// Option 2. Fractional number
var value2 = 23.56;
// Option 3. the number class contains an integer
var value3 = Number("45" );
// Option 4. the number class contains an integer
var value3 = new Number("45" );
</script>
To work with a number (round a number, convert a number from the 16 hexadecimal system to the 10 decimal system, etc.) use the class
Number
Flag
In the JavaScript flag can be true or false
Html
<script>
// flag
var IsReading = true;
// we will see on the screen true
alert (IsReading);
</script>
Date & Time (year month number hours minutes seconds)
To work with the date and time, use a class
Date
Html
<script>
// date and time
var Birthday = new Date(2019, 0, 11, 15, 10, 25);
// display the date
// January 11, 2019 15:10:25
alert (Birthday.toString());
</script>
All data and objects in the JavaScript