Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JavaScript Switch Case – JS Switch Statement Example
- JavaScript Switch Case – JS Switch Statement Example
- There are times in JavaScript where you might consider using a switch statement instead of an if else statement.
- switch statements can have a cleaner syntax over complicated if else statements.
- Take a look at the example below – instead of using this long if else statement, you might choose to go with an easier to read switch statement.
- const pet = "dog";
- if (pet === "lizard") {
- console.log("I own a lizard");
- } else if (pet === "dog") {
- console.log("I own a dog");
- } else if (pet === "cat") {
- console.log("I own a cat");
- } else if (pet === "snake") {
- console.log("I own a snake");
- } else if (pet === "parrot") {
- console.log("I own a parrot");
- } else {
- console.log("I don't own a pet");
- }
- for more:http://besturl.link/jRYt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement