hello guys welcome to the next blog on JavaScript tutorial for beginners in this blog we will see how to use switch statements in JavaScript so let's get started for example I have a variable called score okay and this indicates the score of some student and I will initialize it with 90 right and I'm also going to initialize our variable called result to print some result okay now the syntax of switch statement so switch statement is also a kind of statement in which you evaluate some expression and then on the basis of expression you give your result or you perform some piece of code okay so let's see what is the syntax of switch statement so you use the keyword called switch and then inside these round bracket comes your expression and then inside the curly braces comes the cases on the basis of which you execute some code okay so this is some expression an expression means some condition on the basis of which you decide which case you will perform okay so expression can be score here okay so for example a student is scoring some marks and on the basis of marks we want to display some messages okay so in this case score is an expression and we are evaluating scores and on the basis of scores of student we will perform some code and inside the switch statement comes that cases okay so you can add a case something like this with this colon and then you can perform your code so for example I just want to assign result is equal to some text for example very good okay and once your Kuh is finished you break your switch statement with a keyword called break okay now in front of case comes your value so for example we want to say if our score is equal to 90 then we will return a result very good so here comes your value okay now you can define multiple switch cases inside a switch statement for example something like this and here you can say students scored 60 here you can say students scored 44 even for example and here we can just return good and Fe scores 40 we can return okay right now for example student doesn't score 90 or 60 or 40 then in which case it will go okay so for this we have a default case right so just write a default keyword here and then you say result is equal to unknown okay so default condition is executed when neither of the cases are true okay so if the student doesn't score 90 or 60 or 40 then it will go to the default case right now let's return our result and print it using this document dot get element by ID and demo is the ID of this paragraph tag here and I'm just assigning a result which is this variable here okay so save your code and just notice here that score right now is 90 right so I will refresh my webpage here and say is very good because score is 90 let's say score is now 60 save your code and refresh it once again and now the message is printed good right now let's say score is 45 which doesn't satisfy any of the cases then when we go to our webpage and refresh it it says unknown right so this situation is handled by the default condition right now you can also use some situations in switch cases without the break keyword right so for example I can also write case is equal to hundred here and for example one more case ninety five here and if you notice here I am NOT writing the break keyword after this switch case right so what happens when you don't add a break keyword after a switch case so let's save our code and let's say our score is 95 okay which is this condition and save our code and refresh the webpage and it says very good okay so what's happening here so in the case where the break is not added then it will jumps to the next case and whatever the code in the next case it will execute that code okay so the program flow will be something like this our switch case will ever aloo 800 and the case is not hundred so it will go to 95 and it finds that 95 is the expression we are looking for but there is no break here so I will switch to the next case and in here the case is 90 and here this message is assigned to the result and then if we find that here is the break and then the switch case is broken and then you got your result okay so if you don't add a break after your case it will jump to the next case and perform the code which is under the next case and then if it has break then it will break your switch statement okay so if you want to you know evaluate multiple expression continuously then you use case without a break so in this way you can use switch statements in JavaScript I hope you have enjoyed this blog