Hello and welcome back.
In this video we're can talk about variables.
Let's go over to HD docs.
Let's click on learn basic javascript control shift and type in 0 6 variables.
OK I'm going to close that with the sublime and I mean right click on variables and we'll do a new file
names index that each terminal that I've been HD you know and we'll do the script right here.
So do the script and inside of there I'm going to do council log.
Hello world.
OK I'm a right click open the browser inspect that hello world.
Beautiful.
OK.
So what I want you to do is delete that and then return again.
Let's go to a 9/11 tab and now we're going to talk about JavaScript variables are containers for storing
data values.
So for example if I did var x equals 5 var y equals 6.
And var z equals X plus Y.
OK.
And I right click and open in the browser not the folders I open in the browser and I inspect this and
go to the council.
So I'm going to show anything because I'm not doing council that log.
I'm doing just a regular variable here which is fine.
But if I go to open in the browser and inspect and I do this same thing.
So we've got the lines are here so if I go to the council and I hide the errors right now and we do
var x equals five var y equals six far z equals X plus Y and I clear it right then if I do Z it's going
to be eleven so twenty five plus six.
If I do X it's five.
If I do y it's six.
So
and zi is X plus Y.
So let's clear that for a second and I'll try this one more time.
So if I do x that's five.
If I do y that's six and if I do X plus Y
It's 11:00 now.
What.
What it did here is it stored the variables.
So I did var x equals 5 var y equals sex and var z equals X plus six or five plus six depending how
you look at it.
So it stored it in this web browser because this is the council that log area.
This is the council's you can run commands through this.
And once we close the browser out then it will be gone.
So another example that I'm going to use.
First I want to write it out on sublime and then we're going to run it in the colors of that log.
So it's much like algebra.
We're gonna do var price 1 equals 10.
Var price 2 equals 20 var total.
Equals price one plus price 2.
OK.
And when I do something right click and open in the browser we're going to inspect this and let's look
at the script here.
So we got our price equals 10 var price two equals 20.
So now if I do X such as if it works.
Yep X is still there.
Y is still there.
Is still that.
So it's clear that and no man to do var price 1 equals 10.
Var price 2 equals 20 and let's do our total equals price one plus price to close that clear it and
we'll do total and it's 30 because we've got 10 plus 20.
Now if we wanted to see another way you could do it as you could do price 1 that's 10.
Price 2 is 20.
So you do price one plus price to
give you 30.
So that's another way you can do it.
That's with you know different ways of doing it and programming just like in algebra.
We use variables like price one to hold values and programming just like an algebra we use variables
and expressions total equals price one plus price to from the example above you can calculate the total
to be 30.
So price 1 was 10.
Price 2 is 20 and it equals 30.
So that's variables variables like I said our containers that store data so that you can call on them
later you know.
So you could call total you could do total plus price one right.
If you wanted to.
So total is 30 price one is 10.
So we should get 40 and we do.
We can also do total plus price 2 and that's 50 because you got 20 plus 30 because we're adding the
total price 1 and price 2 and we're also adding price 2 to that total as well as we're adding price
to twice and then price 1 once but they're bunched together because it's the variable is total so that's
confusing and you don't really want to do it like that.
So to speak but it's okay in certain instances.
So let's clear this out and we can talk about one more thing or we can talk about JavaScript identifiers
so all javascript variables must be identified with unique names these unique names are called identifiers
identifiers can be short names like X and Y or more descriptive names like age sum total value volume.
The general rules for constructing names for variables unique identifiers are names can contain letters
digits underscores and dollar signs names must begin with a letter.
Names can also begin with a dollar sign an underscore but we will not use that.
I will not be using that in this course.
Names are case sensitive.
Why and why are different variables so capital Y lowercase y reserved words like Javascript keywords
cannot be used as names.
So that really kind of tells you everything you need to know about variables in terms of the basics
so that when we build the project you'll understand what's going on.
And like I said when we build the project I'll walk you through step by step and show you exactly what
you need to do and and what why we're doing what.
So that it's very well explained.
So with that in mind I'll see you in the next video.
Thanks Roger.