I know we spent quite a bit of time on variables, and this is going to be the last lesson to wrap up
some more information about variables and data types, because they are so super important as the fundamental
core building block when you are programming, so when you are creating a variable.
So as mentioned in the last lesson, when you first initialize it, it's initialized as undefined.
And when you declare a value, declare a variable to it, then that doesn't necessarily mean that you're
signing a value so you can do it independently or you can do it at the same time.
So by default, it's undefined data type.
And you can see that when you just declare the variable, such as test and output in the console's.
We saw a little bit of that in the previous lesson as well.
You can also declare multiple variables in one statement.
So all we have to do is comma, separate them and these are all going to come out as undefined.
So here we've got an example, really simple example.
So we've got VAR A, B, C, D, or you could use left or const, but of course, const wouldn't make
a whole lot of sense because then you're just declaring a bunch of variables that are supposed to stay
as undefined.
So not great use of cost.
So more than likely you're either using VAR or left, and if you're programming with the six then you
are more than likely using left for that one.
Also the naming conventions so you don't have to use it as Camil case, but as you can see in this example,
user first names.
So when we do create variable names, we try to make them meaningful for what contents we're expecting
to hold in them.
And it makes it a whole lot easier to read your code down the line and also remember what all of these
variables are doing and what information they're meant to be holding and the way that we do that because
we can't include spaces in the variable name.
Otherwise, you're going to throw an error the way that programmers will do this and they write multiple
words and they patch them together using cavalcades.
So the first word would just be lowercase and then the second word would be capitalized.
So here we've got user and then first name.
So first is capitalized and name is capitalized.
Sometimes you might see first name all as just F capitalized.
So all depending on the style.
And this is the preferred way to name variables so that it's easier to read.
And this is again from programming perspective when you are accessing your code and you've got a whole
bunch of code and a whole bunch of lines of code, you're going to be really glad that you named them.
Well, there's also when you are naming variables, you can use underscore you could use dollar signs
and you could use letters and digits.
The only thing is that they can't start with digits.
They have to start with either one of these to underscore the dollar sign or a letter so it can't start
with a digit.
They can be upper and lower case, no spaces and it is case sensitive.
So if you got a variable with all uppercase, it's going to be a different variable than with all lowercase.
There's also no limit to the length of the variable name.
But of course you want to keep it manageable and you don't want it having to be too long because variables,
typically you're typing them quite often in the code.
And trust me, you don't want to make them too long.
There's also some reserved words.
There's not a whole lot, but there are some reserved words.
And this is available at the Mozilla Developer Network.
So JavaScript reference lexical grammar.
So these are the reserved words.
So you can't call your variable const const or let let doesn't make a whole lot of sense and you've
got to avoid these words and everything else is OK.
There's also a future reserved words that you got to be mindful of.
So when you are naming your variables, do take a quick glance at this and just to keep it in the back
of your head that when you are naming your variables, that you don't name them as observed word.
And if you do by mistake, then you're going to throw an error on that one.
So the challenge for this lesson is to create some variables, update the values and output them into
the console, and also use the code block for checking to see if a variable is true and output a message,
a secret message into the console.
And then you can change that to false and see if you get a different output.
So very similar to what we did in the last lesson.
But it is meant to get you to practice and get comfortable with variables and this time focus more on
what the names of these variables are as they relate to the content that you're holding within them.
And then also try the Campbell case so that you have different variables that might have longer names
to them.
So go ahead and pause the video and I'll show you the solution coming up.
And here's a quick peek at the code snippet that we're going to be working with.
So the first thing that we're going to do is declare a variable and we're going to assign a value of
two to it.
So this is going to be a concert that we're going to be using and then also declare a variable.
So message.
And here we can have a welcome message to the website and then also declaring a variable.
But we're not going to have any content in it.
And we're use Kemakeza in order to name that variable and we can cancel out the value of more stuff.
So let's see what happens.
And there's also another thing that you could do within the console.
So if you do have variables, you can just simply type them into the console and you can see that instead
of undefined, the response back from the browser is going to be the value that's being held within
the variable.
So, again, this is super useful when you are debugging your applications and you maybe want to know
what a variable value is at a certain time, you can console log it out or you can go into the console
and type the variable.
So next, let's check to see if test is true.
And if it is, then we're going to do something else so we can console, like the value of message and
then also update more stuff.
So we've got a bunch of stuff happening in here.
So this can be whatever values you want to set.
And then also we're going to set value of in block and this is secret within the block.
So no, not much of a secret message, but you can use your creativity and your imagination to come
up with something even more interesting than that.
And of course, I'm sure you can and then just console that out.
So let's try that out so we see that.
Welcome to the website.
This is the secret within the block.
Yes.
Content is here.
So let's toggle this and let's switch this to force and refresh again.
And you see that all we getting output is undefined because, of course, test isn't running because
this is false.
And all of this information is just within this block of code.
So try to have some fun with the experiment.
And coming up next, we're going to look at how to create interaction.
So using the prompt where we can get information coming from the user and that's going to start with
our user interaction and JavaScript.