In the next part we'll look at another core building block of programming: functions! We'll also move on to using script files instead of a snippet of code in an event sheet. switch statements with case and default labels.Formatting (such as whitespace and optional braces).In this part we've covered various features that control how code executes, also known as control flow, including: It's worth knowing how switch statements work as they are commonly used so you're likely to come across them. However in many cases a series of 'if/else if' statements will do the same job. ngn chn iu ny, bn phi thm lnh break sau mi trng case (nh bn c th thy trong v d trn). If the variable value does not match any of the case blocks, then the code present in the default will be. ![]() Why use a switch statement? It can be a concise way to match a long list of possible values. Cu lnh switch thc thi tng dng (tc l cu lnh bng cu lnh) v mt khi JavaScript tm thy mt mnh case c nh gi l true, n khng ch thc thi code tng ng vi case, m cn thc thi tt c cc mnh case tip theo. The Switch Case allows us to add a default case. It's similar to an 'if' statement with the condition number = 5 || number = 10. ![]() The reason is case 5 is allowed to fall through to case 10 and run the same line of code. Now if number is either 5 or 10, it will log Number is 5 or 10!.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |