forked from aayushyadavz/JavaScript-Full-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.js
More file actions
49 lines (40 loc) · 974 Bytes
/
switch.js
File metadata and controls
49 lines (40 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Switch
const month = 3
switch (month) {
case 1:
console.log("January");
break;
case 2:
console.log("February");
break;
case 3:
console.log("March");
break;
case 4:
console.log("April");
break;
default: // Note: It's like else, if nothing matches then this will print.
console.log("Default case match");
break;
} // Output: March
const day = "wednesday"
switch (day) {
case "monday":
console.log("1");
break;
case "tuesday":
console.log("2");
break;
case "wednesday":
console.log("3");
break;
case "thrusday":
console.log("4");
break;
default:
console.log("Default");
break;
} // Output: 3
/* Note: If suppose break keyword is not available after any case then it
will execute all the other codes except default.
Note: Break keyword breaks that control flow. */