In the previous tutorial, we talked about the switch statement how and how important it is, in case we want to do a specific thing, depending upon the value of a variable. But there is another alternative for switch statement, which is called if statement. And actually, it's much more important than switch statement and it's commonly used more than switch statement. Let's now create a similar example as this one. Suppose that we have a variable called gender, and the value of that gender variable is male. And again, we want to determine what we want to do if the value of the gender is male.
And what we want to do is devalue and what we want to do if the value of that variable is A female. So instead of using switch, we will use something called if statement. And to create a if statement, you just type if, and then parentheses and inside these parentheses, you add what you want to test. So for example, I want to test to the value and check the value of this gender variable. So here inside these parentheses, I'm going to type gender. And then I'm going to add double equal sign.
And then I'm going to add meal. And remember, when we want to check the type as well as the value, we use triple equal signs. But if we want to check only the value, regardless of the type, we should just use double equal signs. And in our case, we it's better to use triple equal sign and then we add curly braces here and inside here, we type the code that we wanted to be implemented if the value if the value of the gender equals male, so I want just to print as before, I just wanted to be printed on the screen. So I'm going to use console dot log, and I'm going to add male inside it male. And in order to check if it was a female, we can use something called ILS.
If else e L is E, and then if and again, parentheses and inside them you just add gender, gender and then equals, triple equal sign, and then female. And, again, curly braces. And again, you can add console log. One more time here and change from male to female. See male and finally We can add something called else. And and what else means is that if the value does not equal the first one, and also if it doesn't equal the second one, it is going to implement this value, meaning that this is some kind of a default, as we learned before.
In switch switch statement. It's the default value. So here I'm going to use console dot log. And then I'm going to say gender has not been chosen to choosing. And let's save now and run. And if I save and run, I get mail because the current value of gender is male.
If I change this to female, the male if I save and run, I get female. But if the value of gender has not been specified at all, if it's undefined if I save and run it Yet gender has not been chosen. So as you can see here, in if statement, what we do is just we add if for the first value and then else if for other values. Of course here we can add more ifs here. For example, if we have a variable that has more than one value that has more than two possibilities, we can add here is F's, and then we add ales for the default value