1
00:00:00,450 --> 00:00:04,650
We touched on variables in the introduction of this course.

2
00:00:04,650 --> 00:00:11,340
Variables are a very important concept to understand when it comes to programming in any language including

3
00:00:11,340 --> 00:00:15,950
javascript unlike javascript constants.

4
00:00:16,180 --> 00:00:23,110
Variables are named containers that can store a single value or multiple values.

5
00:00:23,110 --> 00:00:29,030
These values can change based on user inputs or other factors.

6
00:00:29,050 --> 00:00:34,030
Let's take a look at a basic example of how variables can be used to store values

7
00:00:36,980 --> 00:00:38,730
in this javascript code.

8
00:00:38,780 --> 00:00:41,510
We've declared three variables.

9
00:00:41,510 --> 00:00:44,600
Variable X Y and Z.

10
00:00:46,650 --> 00:00:55,340
You can think of each variable as a container the variables each contain their own value the value of

11
00:00:55,340 --> 00:01:01,400
variable x is 10 the value of variable Y is 15.

12
00:01:01,400 --> 00:01:06,470
The value of variable z is equal to the sum of variable x and y.

13
00:01:07,160 --> 00:01:14,380
Which in this case would be twenty five or ten plus 15.

14
00:01:14,390 --> 00:01:22,730
Now let's output the value of c Using the get element by IED output method will output the result in

15
00:01:22,730 --> 00:01:25,280
a paragraph with the IED.

16
00:01:25,310 --> 00:01:25,820
Demo

17
00:01:33,100 --> 00:01:36,790
now let's save our file and preview it in our web browser to see the results.

18
00:01:49,440 --> 00:01:57,190
Here we can see our heading javascript variables in our paragraph working with variables and underneath

19
00:01:57,190 --> 00:02:00,610
that we can see the result has been output.

20
00:02:02,410 --> 00:02:10,360
So variable X has been added to variable Y and the result has been output it to 25

21
00:02:18,480 --> 00:02:26,930
in our example the X Y and Z name we attach to the variable are known as variable identifiers.

22
00:02:27,480 --> 00:02:35,970
Each variable you declare must have a unique identifier we used very short identifiers but as we progressed

23
00:02:35,970 --> 00:02:45,120
through the course we will be using more descriptive identifiers for example color shape size age and

24
00:02:45,120 --> 00:02:51,200
weight these would all be considered more descriptive.

25
00:02:51,260 --> 00:02:59,650
There are some general rules when selecting identifier names names can contain letters digits underscores

26
00:02:59,830 --> 00:03:08,200
in dollar signs names must begin with a letter names are case sensitive.

27
00:03:09,890 --> 00:03:14,780
Reserved words like Javascript keywords cannot be used as names.

28
00:03:16,990 --> 00:03:26,710
Javascript variables can hold numbers like one hundred or ten point five or text values for example.

29
00:03:26,710 --> 00:03:27,490
John Smith

30
00:03:30,560 --> 00:03:33,980
text values are known as text strings.

31
00:03:33,980 --> 00:03:41,540
Strings must be written in single or double quotes numbers can be written without quotes.

32
00:03:41,580 --> 00:03:44,970
If you put quotes around a number it will be treated as a string

33
00:03:48,130 --> 00:03:49,740
for the sake of this example.

34
00:03:49,780 --> 00:03:57,890
Let's change our numerical value 15 to a text value.

35
00:03:58,150 --> 00:03:59,420
Now when we save our file

36
00:04:02,690 --> 00:04:10,770
and refresh our browser we can see that the numerical value 10 stored within the x value variable

37
00:04:13,360 --> 00:04:19,870
has been attached to the string contained within variable Y.

38
00:04:19,870 --> 00:04:24,480
The output is contained within variable Z.

39
00:04:25,980 --> 00:04:27,750
Which equals X plus Y.
