MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/v1jj0c/switch_statement_explained_for_beginners/iarsspn/?context=3
r/learnjavascript • u/elediardo • May 31 '22
19 comments sorted by
View all comments
16
Also, your switch statements can now include blocks:
switch(grade){ case "A": { const message = "Great job!"; console.log(message); break; } case "B": { const message = "OK Job"; console.log(message); break; } ...etc... }
whereas without:
switch(grade){ case "A": const message = "Great job!"; console.log(message); break; case "B": const message = "OK Job"; // ERROR - const message already declared console.log(message); break; ...etc...
}
1 u/[deleted] Jun 01 '22 Cna you do put an if statement inside ? 2 u/pookage helpful Jun 01 '22 Yup! It's still javascript - you can do whatever you want inside.
1
Cna you do put an if statement inside ?
2 u/pookage helpful Jun 01 '22 Yup! It's still javascript - you can do whatever you want inside.
2
Yup! It's still javascript - you can do whatever you want inside.
16
u/pookage helpful May 31 '22
Also, your switch statements can now include blocks:
whereas without:
}