1
00:00:00,630 --> 00:00:03,540
Hello and welcome to this video.

2
00:00:03,600 --> 00:00:14,430
In this video I will be introducing you to JavaScript variables what are variables in JavaScript javascript

3
00:00:14,430 --> 00:00:24,960
variables are containers for storing data values in order to create a variable you need to use the var

4
00:00:25,180 --> 00:00:31,320
key word which is spelled thi r he has to be in lowercase.

5
00:00:31,530 --> 00:00:39,180
Also when you create variables creating variable means declaring variables is the same P when you declare

6
00:00:39,180 --> 00:00:52,290
variables you have to assign a value to variables and you use the equal sign to assign values to a variable.

7
00:00:52,290 --> 00:00:59,970
For example if I wanted to create a variable X I'm going to give it a value of 7.

8
00:00:59,970 --> 00:01:08,040
Also if I want to create a variable called say my car and I give it a value of posh.

9
00:01:08,760 --> 00:01:19,020
When you are creating variables is always good practice to name your variables closely to what they

10
00:01:19,020 --> 00:01:23,250
are going to store the type of data they are going to store.

11
00:01:23,250 --> 00:01:30,810
Example I have named this variable my car which is an indication that the type of data I'm storing is

12
00:01:30,810 --> 00:01:35,710
relating to cars not is it to difference in the two values here.

13
00:01:35,730 --> 00:01:40,560
This one here the values 7 which is in number and note is here.

14
00:01:40,560 --> 00:01:47,010
The value here support and I've put quote around it when you are declaring variables.

15
00:01:47,010 --> 00:01:53,730
If you are declaring a text you have to enclose it in quotes.

16
00:01:53,820 --> 00:02:00,660
You either have to use single quotes or double quotes but you can't mix them you can't use a single

17
00:02:00,660 --> 00:02:03,120
quote here and then a double quote here.

18
00:02:03,240 --> 00:02:08,900
That's the only way the computer will understand that it is dealing with a text.

19
00:02:08,910 --> 00:02:12,030
You need to include the values in quotes.

20
00:02:12,030 --> 00:02:16,890
You don't need to do that with numbers because a computer knows that there is a number but if you want

21
00:02:16,890 --> 00:02:20,300
a computer to know that is a string they call it a string.

22
00:02:20,310 --> 00:02:23,150
In programming you want to know that this is a string.

23
00:02:23,160 --> 00:02:26,060
You need to include it in quotes.

24
00:02:26,070 --> 00:02:30,600
Also notice I've used semicolons here which is important.

25
00:02:30,600 --> 00:02:34,590
That indicates that that is the end of that statement.

26
00:02:34,650 --> 00:02:39,920
A javascript program is basically a collection of statement.

27
00:02:39,930 --> 00:02:42,190
This indicates this is one statement.

28
00:02:42,330 --> 00:02:46,470
These indicate this is another statement because of the semicolon.

29
00:02:46,470 --> 00:02:50,910
So you have to do that when you're declaring variables.

30
00:02:50,910 --> 00:02:55,710
You can also declare variables without assigning them a value.

31
00:02:55,710 --> 00:03:01,140
So when you declare a variable without a value it is known as on defined.

32
00:03:01,170 --> 00:03:09,240
Once you have defined or declared a variable you can change its value.

33
00:03:09,270 --> 00:03:12,150
For example you have already defined a variable called my car.

34
00:03:12,150 --> 00:03:16,090
If I wanted to change the value from posh for example to a range rover.

35
00:03:16,110 --> 00:03:23,670
All I need to do is call the variable by name and assign it a different value so that we already change

36
00:03:23,720 --> 00:03:25,560
changed value once you've declared a variable.

37
00:03:25,560 --> 00:03:36,020
You can change the value a variable that is declared without a value is known as on defined.

38
00:03:36,250 --> 00:03:42,750
Also it's very important to know that JavaScript is case sensitive.

39
00:03:43,320 --> 00:03:46,360
So for example here declared this variable.

40
00:03:46,650 --> 00:03:47,610
My car.

41
00:03:47,650 --> 00:03:55,130
Car with open case see if I tried to reference it with a lower case c it will not work.

42
00:03:55,140 --> 00:04:07,470
You can experiment with JavaScript inside your web browser console if you are using a Mac you can access

43
00:04:07,470 --> 00:04:15,390
to a web browser console by clicking on option command and J what you call the web browser open.

44
00:04:15,840 --> 00:04:22,200
If you are on a Windows based computer once you've got the web browser open you can just press F 12.

45
00:04:22,200 --> 00:04:25,340
That will give you the Web console.

46
00:04:25,390 --> 00:04:34,650
I've got the Google home page open so I'm going to access the web console just by hitting the F 12 on

47
00:04:34,650 --> 00:04:38,250
the keyboard and that will give me the console through this.

48
00:04:38,370 --> 00:04:46,680
This is the developer console where you can experiment with JavaScript so there are different ways you

49
00:04:46,680 --> 00:04:47,800
can docket.

50
00:04:47,830 --> 00:04:51,720
So if you click here at the moment is dock to the side.

51
00:04:51,720 --> 00:04:58,890
You can also dock it to the bottom and that will give you the page to web page you currently view and

52
00:04:58,890 --> 00:05:06,490
then you can expect with a code on the side or you can do it on this side dock it to the left.

53
00:05:06,490 --> 00:05:13,200
So depending on whatever you fancy you can take it wherever you like.

54
00:05:13,210 --> 00:05:17,780
I'm going to Joe's docket on the need for now.

55
00:05:17,770 --> 00:05:26,350
So let's try and experiment with some javascript so I'm gonna declare a variable inside the console

56
00:05:26,350 --> 00:05:26,980
here.

57
00:05:27,070 --> 00:05:36,720
Just type in VR to declare a variable and I'll give the variable a name of X give you the value of 7.

58
00:05:38,110 --> 00:05:42,700
So now if I want to call this variable all I need to do is call the variable by his name.

59
00:05:42,700 --> 00:05:47,330
If I press X it will return the value of 7.

60
00:05:47,410 --> 00:05:51,890
Now that I've declared the variable i can also change its value.

61
00:05:51,940 --> 00:05:55,150
All I need to do is call it by its name.

62
00:05:55,300 --> 00:05:59,330
Use the equals 2 and assign it a different value.

63
00:05:59,350 --> 00:06:05,670
Now if I call the variable x again in the longest 0 7 both in our stores 8.

64
00:06:06,010 --> 00:06:12,190
Same thing 5 declare another variable called let's declare a new variable.

65
00:06:12,190 --> 00:06:16,560
I'm gonna call this variable my car.

66
00:06:17,950 --> 00:06:18,430
Okay

67
00:06:23,140 --> 00:06:23,850
my car.

68
00:06:24,440 --> 00:06:33,140
Okay you know I'll give you my car and I'm gonna give it a value of see Pausch.

69
00:06:38,940 --> 00:06:40,480
Okay.

70
00:06:40,590 --> 00:06:44,880
And I need a semicolon to end that.

71
00:06:44,930 --> 00:06:54,520
So now if I call these variable by its name if I say for example if I call call it by car.

72
00:06:56,110 --> 00:06:57,120
It will not work.

73
00:06:57,130 --> 00:06:57,640
You know why.

74
00:06:58,150 --> 00:07:01,210
Because I've referenced it in lowercase.

75
00:07:01,210 --> 00:07:04,020
You know the C I use this an uppercase.

76
00:07:04,060 --> 00:07:09,400
So it's very important that you reference two variables the way you've defined them.

77
00:07:09,400 --> 00:07:17,820
If I now go back and call it again with uppercase C it should return the right.

78
00:07:17,860 --> 00:07:20,560
You can see it's giving me the value of posh.

79
00:07:21,190 --> 00:07:25,870
Once you've declared a variable you can easily change its name change its value.

80
00:07:26,410 --> 00:07:30,810
So if I want to change that to something else I'll just call it by name.

81
00:07:32,560 --> 00:07:36,390
So I want to change this to a Ford for example.

82
00:07:39,770 --> 00:07:40,950
All right.

83
00:07:41,640 --> 00:07:44,010
And to a semicolon.

84
00:07:44,010 --> 00:07:45,100
Now that's changed.

85
00:07:45,120 --> 00:07:51,050
If I call the variable again by name it will no longer store render right.

86
00:07:51,080 --> 00:07:53,320
Will be now storing Ford.

87
00:07:53,370 --> 00:08:01,560
So these are some of the basic examples you can use to play around in the pros and cons of the console

88
00:08:01,560 --> 00:08:05,960
is very useful for playing around with little little look to values like this.

89
00:08:06,360 --> 00:08:09,720
So you can experiment and get acquainted.

90
00:08:09,720 --> 00:08:14,190
So that's it for this video on javascript variables.

91
00:08:14,190 --> 00:08:16,050
Many thanks and bye for now.
