WEBVTT

00:01.310 --> 00:09.210
The concept of variables is a core concept not only javascript but in most programming languages.

00:09.770 --> 00:14.990
I want to splain you what variables are by using an analogy.

00:15.070 --> 00:23.650
Variables are a bit like boxes that have a certain label on them so they have a name and you put a value

00:23.950 --> 00:30.580
where many values in these boxes you store information in these variables and then you can retrieve

00:30.670 --> 00:38.350
that information back or you can modify what's in there so I can have a box that has a label name and

00:38.350 --> 00:46.070
I can put in there a piece of text is what we call a string that's just text that says Pablo.

00:46.120 --> 00:49.660
And then I can ask OK what's in the box labeled name.

00:49.660 --> 00:52.330
And the answer will be Pablo or I can change what's in there.

00:52.330 --> 00:58.970
I can say OK now in the box name a name we are going to store another name.

00:59.170 --> 01:02.530
So you can store these variables pretty much anything.

01:02.850 --> 01:11.040
It can be number names whether something is true or false or collection of elements.

01:11.280 --> 01:15.410
What we call our race will occur later on in the course.

01:15.570 --> 01:19.550
And more custom more complex objects as well.

01:20.110 --> 01:22.160
So that's that's that's about it.

01:22.510 --> 01:24.670
Let's see how we can create them.

01:24.700 --> 01:27.830
So I have an empty document here.

01:27.850 --> 01:29.750
I have my web browser open.

01:29.890 --> 01:36.060
See how I have the console open as well because we're developing javascript so we want to see if we

01:36.100 --> 01:41.280
make any errors where they'll show here or if we want to see the value of a variable.

01:41.340 --> 01:50.260
We're also going to show here we're not going to get into modifying or accessing the DOM hate mail until

01:51.220 --> 01:56.230
the very end of this course because we need to learn the basic tools first we need to get comfortable

01:56.230 --> 02:01.030
with coding in javascript before we can make more complex things.

02:01.030 --> 02:11.220
So let me get started by opening a script tag and we'll define our first variable.

02:11.360 --> 02:13.270
I'm going to call it name.

02:13.430 --> 02:17.380
So see how I'm using the keyword fire to define a variable.

02:17.420 --> 02:20.980
I'm going to call it name and I'll give it a value.

02:20.980 --> 02:23.470
That's why I'm using the equal sign value.

02:23.500 --> 02:26.030
It's going to be your name.

02:28.440 --> 02:30.510
And I want to see this.

02:30.560 --> 02:32.670
Have this shown in the console.

02:34.800 --> 02:41.200
So this is how I can get an x get access to this variable just by writing its name.

02:41.610 --> 02:47.900
And I'm going to reload the page now see how it's showing me the value that I enter here.

02:47.910 --> 02:54.590
It could be if I read of the page again it's going to be this one.

02:55.020 --> 03:06.110
So I mentioned variables can also be numbers like undefined two numbers or I can't do it like this.

03:06.110 --> 03:10.080
Which is exactly the same.

03:11.990 --> 03:16.240
And I can I can do operations as well.

03:17.550 --> 03:19.410
So I can do something like this.

03:20.800 --> 03:26.140
And that's show the console show this in the console.

03:26.200 --> 03:29.790
You'll get the result of three.

03:30.060 --> 03:31.320
So that's about it.

03:31.320 --> 03:35.100
That's a quick introduction to variables.

03:35.100 --> 03:41.110
Variables are a bit like boxes that have a label and there's basically two things you can do with them.

03:41.160 --> 03:47.870
You can put a value in a variable or you can get a value from a variable which you are doing here.

03:49.230 --> 03:55.920
Before moving on to the next lesson I'm going to show you how to write comments in Javascript code.

03:56.070 --> 04:03.380
So what we have here is a variable find us 10 and then we are a hundred to these values.

04:03.390 --> 04:05.680
So this will take the value of 110.

04:05.880 --> 04:07.100
You can see in the web browser

04:09.780 --> 04:16.590
because we're humans sometimes we don't understand what what's in the code or we not remind ourselves

04:16.590 --> 04:18.260
for the future what we are doing.

04:18.420 --> 04:20.530
All we want to communicate with our team.

04:20.640 --> 04:29.830
So you can write comments that don't get evaluated as expressions by using these two slashes.

04:30.060 --> 04:37.470
So this is a comment that is for me to read or for somebody else in my team to read but it does not

04:37.470 --> 04:40.200
change anything of what's going on.

04:40.200 --> 04:45.690
Sometimes you people use the expression common something out like comment this line out.

04:45.690 --> 04:50.910
In this case I'm commenting this out which means that I'm turning that line into a comment and then

04:50.910 --> 04:52.410
it's no longer evaluated.

04:52.470 --> 04:56.960
If I reload the page you'll see that this hasn't been executed.

04:57.210 --> 04:59.580
It's not even checked for syntax errors or anything.

04:59.590 --> 05:02.730
So just a comment for human being to read.

05:02.730 --> 05:10.860
You can write Kommissar multiple lines by using force slash an asterisk and then you can start writing

05:10.860 --> 05:16.460
your comment like this and then eventually you close it like this.

05:16.470 --> 05:23.520
That's a multi-line comment on these kind of comments they don't get evaluated they don't get executed.

05:23.530 --> 05:27.660
They're only for human human to human communication.
