You've seen brief glimpses of them before in the earlier lessons, they're variables and they're used
all over the place in programming, they're one of the four core fundamentals of any programming, language
and a variable.
What it is, is it's allows you to hold information in a value.
So if you're typing out a really long paragraph, like I really, really enjoy working with JavaScript
and you want to have that message and maybe even update that message, well, the best place to place
it is within a variable.
And then you can reference it just by using variable message and then you can always get that information
back in.
Variables are assigned so they can assign values to them by using the equal sign.
So variables when we are trying to use them, you need to declare them as well.
And in order to declare a variable, that's where that var came in.
And we did see this earlier where we were declaring variables of A, B, C and so on.
So we're using variable X to equal one.
So they could be numbers, they can be strings.
And there's more on this coming up in the upcoming lessons.
So for now we can see that we've got a variable we can console logout its value.
So referencing the variable by the name.
So if we want to set a variable X to equal one, then we can use console log and return back that variable
value just by referencing X.
And then we can also update the value that's contained for X and we can set it to two or whatever value
we want.
And in JavaScript it's dynamic typing so we can switch between different types so we can have numbers
and strings.
And of course, more on this later on in the lesson.
So there's a quick challenge for you in this lesson and that's to declare a variable.
You can use a simple variable name such as ABCDE e whatever you want, and then or you could call it
message and then update that value to a new message and then also declare a variable that holds your
name and then change it to your friend's name and output it in the console.
So that's the challenge.
And there's a code snippet to go along with this.
So you can see that we're first starting out by console, logging out the value of a as so setting it
as hello world and logging it out.
And then we've got welcome back and we're logging out that variable of eight again and we're going to
see it's got a different message and then we're setting a name and we're console logging out the name
and then we're setting the name of our friend and we're console logging out that name.
So let's try that out so we can pause the video here and write the code opening brackets.
First, we're going to declare a variable.
So we're going to just use a as a basic variable.
And there are some rules which we are going to be covering later on.
So setting the variable value of a two hello world.
And now if I go into the console, if I type out A, I can see how the world gets returned back.
And if I want to see it directly within the console without having to type A, I can console log that.
And when I refresh, I see how the world is written in my console.
So the objective of this lesson was also to assign a new value to a.
So once I've declared a I don't have to redeclared again.
So I'm not using VAR again because that information is contained already within the variable of a so
I don't have to declare it again, but I can reassign values with the equals sign.
So this is just that one equals sign and we want it to write in a usage of welcome back to that value
of eight and then logging out the console message one more time.
So now you can see that initially when we come in, the value of a hello world and then next time we
output the value of a it's changed to welcome back.
And there is a second part to this challenge that was to create a name.
So giving your name within the variable value and console, logging out that my name variable and then
taking the my name variable and assigning a new value to it.
So in this case, I'm going to sign it to John and then once again console logging out my name variable
and seeing the changes.
So you can see that we were able to declare the variable with the value, assigning a value to it as
we declared it.
And then we updated the value and we have different values coming back in the output.
So coming up next, there is a little bit more information on variable, so we need to cover.
That's still to come.