When you write the code almost every time you want to perform different actions for different decisions,
for that we frequently use conditional statement in our code.
Generally, a conditional statement is the part of decision making in JavaScript, the conditional statement
is a statement that will evaluate condition to be either true or false.
As your JavaScript programs get more sophisticated, you will need to make use of conditional statements
that allow your program to make decisions.
Nearly all other programming languages use conditionals, and JavaScript is no exception.
What do we want the block of code to be executed if a specified condition is true or false?
We use if our statement if you take a look on the screen, you will see the general structure of if
statement it starts with if keywords, which is followed by the condition inside the Brace's, the condition
which should be checked.
If it is true or false, then we have the block of code inside the collaborator's and it's executed.
If the condition is true, if it's false, then the code inside the statement will run.
All right, let's go to Brackett's and create the variables my child equals to Alexis.
And then variable gender equals.
To me.
Now, let's use F.L. statements and check the following condition.
So if gender three equals to male.
Then run in council.
My child plus is my son.
And if the condition is false, then in a statement, again, running Castle, my child.
Plus is my daughter.
So in this statement, we have the condition gender triple equal to male, and we need to check if it's
true or false, Alexis can be denied either for male or for female.
And we wonder how the parents should call him or her.
So you see that condition inside the boys.
Is it true?
And therefore, the code in its statement is executed.
We got Alexis is my son.
If we change the gender and write the value as female, then the condition will be false and the block
of code inside each statement will be skipped and the code inside the statement will be executed.
So we have Alexis is my daughter.
If we want to execute code based only on the conditions, true value, then it's not necessary to use
our statement just using if statement is absolutely enough.
So let's get rid of our statement.
You said that the condition is false because of the female value and therefore we don't have result
in council, the block of code inside if escaped, if we change female into male, then we will get
the same result.
Alexis is my son.
Before we finish, I would like to show you something that is very helpful and frequently used, especially
when you deal with a bunch of lines of code, I'm talking about the comments.
They are very useful when you want to either describe the code or post the code.
We have two types of comments, single line and multiline, in order to write a single line comment
we need to use for slashes.
And that the comment you can see that color of code is great.
The text editor makes it different from other working codes and also in JavaScript, Engine says slashes
it understands that this code is commented out and it doesn't executed.
In order to comment multiple lines of code, we can use multiline commenting.
We need to write, slash and start at the beginning of the code and start and slash at the end of the
code.
So you see that whole code is great.
Reload the page and you see that the code is not executed.
All right.
In this lecture, we have talked about conditional statements and commenting.
Let's stop here.
See you in the next video.