Hello, in this JavaScript programming video, I am going to show you conditional statement. So a conditional statement allows you to check if a condition is true. If so, run a certain piece of code. If it isn't, then you could check for another condition, someone's like full back condition. And then ultimately, you could fall back on sort of a default set of code as well. So let's just dive right into it.
Let's create a couple of variables. So no one signs the value of nine keep using you know the value knowing there's no signal honestly significance to It's nothing to do the value that I am positive I have not used yet. 314 which is also the first three digits of pi 3.14. And now the format the syntax of a conditional statement is pretty simple, you put it open close bracket. And in here you put your condition. So let's check if num one is less than num two.
In here, you can put any comparison operator. So the comparison operators that you've used, or anything that can basically return a true or false value you can put in here and you can mix and match them with bracket as much as you want. Those would be no one. If no one is less than two, then you put curly braces like so. And any code within these two curly braces will only run if this condition is true. So we'll do console dot log.
Num one is less than num two. That's pretty, pretty cool. Let's save it, run it see what happened. They said no one is Less than two kept a lot of that. And what would happen if I change this to 100? Nothing, or this check happens.
It's a is 900 less than 314? No, it isn't. Therefore, it just skips this code block and just keep going. The application has no you know, code remaining, it doesn't do anything. So if we want to run another condition, we can tag on an out F, and this will only get checked if this equates to false. So if we do one, right tap, then I'm to sign in greater than num to refresh.
It says num one is greater than number two, but the first one wasn't printed out. And if we change this back to a nine and we Load it says no one is less than num two. So this condition is checked if this equates to true, all of the code not just this one line, if there's more than one line, it could be, you know, a bunch of loops and winter function function calls, which we will get onto very soon. All of the code within the parentheses will be initiated. If this is false, and only then, like the elsif will be caught. So it's a known one is greater than two.
And there are other just weird. There we go, Okay, there are other or when you're on one line, you can put multiple if, else If so, well, obviously in this scenario, these are more Point code. If it's less than that, greater than that the only other option is to check if it's equal to it. And you can also have a fallback, which is else. And if all of the other conditions are the if condition on the outside conditions file, then this code will be called. And if you can think of the default code, default code reload, that will get run if I change this to 14.
So what happens? It says it from grundfos, 14 less than 14? No, no, isn't that the same. So this file, then it goes to the next outfit. It's a if 314 greater than 314. Nope, they're still the same.
So that also file then it goes to this alpha and the alpha and have a condition. So just say let's just run this piece of code. If we reload, it says default fallback code. If you have an else, make sure it's at the end needs to be at the end of your if else statement. You could just have an if else. Or you could have an if elsif.
Or you could have multiple else if as well, obviously, with different conditions, otherwise, the code would be dependent. And you could have known multiple other you know if statements as well, or doing their own, you know, special checks, but that's it. Honestly for conditional statements. If you have any questions, feel free to pop me a message. And as usual, I look forward to seeing you in the next video.