All right welcome back on this video where and talk about javascript syntax so first let's go to H2
docs on our desktop.
Let's double click on learn basic javascript.
Right click the new folder.
I've been 0 3 and we're going to do syntax
Rio.
OK I'm going to close that out what's called a sublime when I close out the previous files.
I'm going to right click on 0 3 syntax to new file.
We're going to do index bandaged him out and then I'm going to control n and demand.
J ust just like the previous videos.
So in the index down age to male file I just want to type an HMO tab and then at the bottom we're gonna
do a script tag as our C and main digests and then close up and then here I want you to do a console
dialog five plus five and then we'll do we'll close that.
I'll save it.
That's right click on the index on HMO file inspect make sure it's working.
There it is.
Okay good.
And the reason why I did that is to make sure that the files are connected so close that closes out
now we're gonna be coding inside of here.
So the first thing I want to show you I'm going to tell you first about what javascript syntax is.
So javascript syntax is a set of rules how javascript programs are constructed.
So for example you have variable X comma Y comma Z and then if I do this and do how to declare variables
OK.
You can assign values by doing X equals five Y equals six how to assign values.
OK.
And then if I do z equals X plus Y
then we do how to compute values.
So the javascript syntax defines two types of values fixed values and variable values fixed values are
called liberals variables value all values are called variables javascript literally is the most important
rules for writing fixed values are numbers are written with or without decimals.
So for example let's do let's come at this out and we'll do javascript laterals.
And I'm going to do ten point five zero and we'll do things like that.
And those are numbers and strings are tax written with double or single quotes.
So like this this would be John Doe there'd be a string or you could do john doe like this
so obviously this is not right in our javascript but I just want to show you the syntax so that when
we talk about this more when we when we cover strings
more appropriately when we cover numbers and strings in the advanced course I'm not going to often in
this course but in the advanced course when I talk about this stuff you want to have an idea of what
these are.
OK.
Next up we have Javascript variables and so for this one this comment is out and we'll do javascript
variables.
So in inappropriate in a programming language variables are used to store data values JavaScript script
uses var VFR keyword to declare variables an equal sign is used to assign values to variables.
In this example or my example I should say x is defined as a variable so I'll do variable var x and
then I can do X equals six okay.
So now let's go to the index on H1 and openness in the browser and inspect.
And we should see a whole bunch of stuff here.
Actually no.
OK here.
Let's do this let's go back to me and J us and I'm going to do that to console that log var x
let's do X equals six.
OK.
Now if I open that in the browser let's open it from the next load age to Mel and I inspect and go to
the council.
It's going to be sex.
Now if I type an x return it's going to be sex because what we did here is X equals sex.
Okay.
So the next thing we're talking about is javascript operators.
So javascript uses arithmetic operators plus minus times divide to compute values solve for an example
for that.
And we'll calls us we're going to do javascript
and we're gonna do five plus
through I guess five plus six times 50.
OK javascript javascript also uses an assignment operator with the equals sign to assign values to valuables.
So just like what we did up here x equals six.
We're gonna do.
Var x comma Z.
And then we'll do X equals 10.
And Zee equals 100.
Then we have Javascript expressions and expressions a combination of values value variables.
Operators which computes to a value.
Okay.
The Pew station is called an evaluation.
So for example ten times let's do 10 times 20 evaluates to.
What would that be.
And there would be 200.
So and expressions can also contain variable value.
So you could do X times ten like that.
So we could do X times 10.
The values can be of various types such as a number such as numbers and strings.
For example you could do Josh boy to put that in quotes so we could do Josh plus blank
plus John
and what that does is it evaluates to Josh John.
So what I do is I added those two together and so it would equal that.
So here let me.
Let's do equals.
Josh John K.
next we're talking about JavaScript keywords so javascript keywords are used to identify actions to
be reformed.
So the VAR keyword tells the browser to create various variables.
So if we did.
Var Z comma a and then close that.
And we did ze equals five plus eight OK.
And then we did a equals eight times
ten times back.
OK.
Then that would show up just like that.
Next we have Javascript comments which is what we've been doing here here here and there.
And this is a commonly used thing where you comment out code because what you want to do and this is
a single line code but not all javascript statements are executed code after double slashes or between
a slash and a star and a star and a slash is treated as a comment.
Comments are ignored and will not be executed.
So what you can do is you can literally do var equals Z let's say right and then let's say that you
wanted to run something else whatevers over to the right of that is not going to be executed.
OK.
Same with that.
So if I just like this none of it's going to work which is the idea.
And then finally we can talk about JavaScript identifiers identifiers or names and JavaScript identifiers
or use the name variables and keywords and functions and labels the rules for legal names are much the
same in most programming languages in JavaScript the first character must be a letter or an underscore
or a dollar sign so Quinta characters may be letters digits underscores or dollar signs.
Numbers are not allowed as the first character this way JavaScript can easily distinguish identifiers
from numbers and Javascript is case sensitive all javascript identifiers are case sensitive the variables
last name and last name are two different variables so if I did for this example let's say that I did
let's do javascript is case sensitive
and we did var last name comma last name.
Those are two different variables so you could do last name equals Bob.
All right.
And then the other one would be last name equals Jones.
OK.
But what it's gonna do is it's going to be two different variables.
And whenever you call one or the other it's going to think that it's calling that one or the other one.
So you want to make sure that when you're making variables that you're conscious of that and you don't
name things similar names because then you might get confused or have issues.
So javascript and camel case historically programmers have used different ways of joining multiple words
into one variable hyphens first name last name Master dash card inter dash city hyphen is not allowed
in JavaScript they're reserved for such attractions underscore first underscore last underscore name
Master on the scorecard entered underscore city camel case would be like this
the first letter of each name is capitalized.
You can also do lower camel case so they would just be the first name.
So like this we could do first first on the name and the second name is capitalized.
The first one is not javascript programmers tend to use camel case that starts with lower case letter
first name last name MasterCard etc..
Javascript character set javascript uses the unicode character set Unicode covers almost all the characters
punky punctuation and symbols in the world.
So with that I'm going to save this real quick.
That's all I have for JavaScript syntax so I'll see you in the next video.
Thanks for watching.