Hello and welcome to this video.
In this video I will be introducing you to JavaScript variables what are variables in JavaScript javascript
variables are containers for storing data values in order to create a variable you need to use the var
key word which is spelled thi r he has to be in lowercase.
Also when you create variables creating variable means declaring variables is the same P when you declare
variables you have to assign a value to variables and you use the equal sign to assign values to a variable.
For example if I wanted to create a variable X I'm going to give it a value of 7.
Also if I want to create a variable called say my car and I give it a value of posh.
When you are creating variables is always good practice to name your variables closely to what they
are going to store the type of data they are going to store.
Example I have named this variable my car which is an indication that the type of data I'm storing is
relating to cars not is it to difference in the two values here.
This one here the values 7 which is in number and note is here.
The value here support and I've put quote around it when you are declaring variables.
If you are declaring a text you have to enclose it in quotes.
You either have to use single quotes or double quotes but you can't mix them you can't use a single
quote here and then a double quote here.
That's the only way the computer will understand that it is dealing with a text.
You need to include the values in quotes.
You don't need to do that with numbers because a computer knows that there is a number but if you want
a computer to know that is a string they call it a string.
In programming you want to know that this is a string.
You need to include it in quotes.
Also notice I've used semicolons here which is important.
That indicates that that is the end of that statement.
A javascript program is basically a collection of statement.
This indicates this is one statement.
These indicate this is another statement because of the semicolon.
So you have to do that when you're declaring variables.
You can also declare variables without assigning them a value.
So when you declare a variable without a value it is known as on defined.
Once you have defined or declared a variable you can change its value.
For example you have already defined a variable called my car.
If I wanted to change the value from posh for example to a range rover.
All I need to do is call the variable by name and assign it a different value so that we already change
changed value once you've declared a variable.
You can change the value a variable that is declared without a value is known as on defined.
Also it's very important to know that JavaScript is case sensitive.
So for example here declared this variable.
My car.
Car with open case see if I tried to reference it with a lower case c it will not work.
You can experiment with JavaScript inside your web browser console if you are using a Mac you can access
to a web browser console by clicking on option command and J what you call the web browser open.
If you are on a Windows based computer once you've got the web browser open you can just press F 12.
That will give you the Web console.
I've got the Google home page open so I'm going to access the web console just by hitting the F 12 on
the keyboard and that will give me the console through this.
This is the developer console where you can experiment with JavaScript so there are different ways you
can docket.
So if you click here at the moment is dock to the side.
You can also dock it to the bottom and that will give you the page to web page you currently view and
then you can expect with a code on the side or you can do it on this side dock it to the left.
So depending on whatever you fancy you can take it wherever you like.
I'm going to Joe's docket on the need for now.
So let's try and experiment with some javascript so I'm gonna declare a variable inside the console
here.
Just type in VR to declare a variable and I'll give the variable a name of X give you the value of 7.
So now if I want to call this variable all I need to do is call the variable by his name.
If I press X it will return the value of 7.
Now that I've declared the variable i can also change its value.
All I need to do is call it by its name.
Use the equals 2 and assign it a different value.
Now if I call the variable x again in the longest 0 7 both in our stores 8.
Same thing 5 declare another variable called let's declare a new variable.
I'm gonna call this variable my car.
Okay
my car.
Okay you know I'll give you my car and I'm gonna give it a value of see Pausch.
Okay.
And I need a semicolon to end that.
So now if I call these variable by its name if I say for example if I call call it by car.
It will not work.
You know why.
Because I've referenced it in lowercase.
You know the C I use this an uppercase.
So it's very important that you reference two variables the way you've defined them.
If I now go back and call it again with uppercase C it should return the right.
You can see it's giving me the value of posh.
Once you've declared a variable you can easily change its name change its value.
So if I want to change that to something else I'll just call it by name.
So I want to change this to a Ford for example.
All right.
And to a semicolon.
Now that's changed.
If I call the variable again by name it will no longer store render right.
Will be now storing Ford.
So these are some of the basic examples you can use to play around in the pros and cons of the console
is very useful for playing around with little little look to values like this.
So you can experiment and get acquainted.
So that's it for this video on javascript variables.
Many thanks and bye for now.