Advertisement
sissou123

Untitled

Mar 18th, 2022
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. JavaScript Switch Case – JS Switch Statement Example
  2. JavaScript Switch Case – JS Switch Statement Example
  3. There are times in JavaScript where you might consider using a switch statement instead of an if else statement.  
  4.  
  5. switch statements can have a cleaner syntax over complicated if else statements.
  6.  
  7. 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.
  8.  
  9. const pet = "dog";
  10.  
  11. if (pet === "lizard") {
  12.   console.log("I own a lizard");
  13. } else if (pet === "dog") {
  14.   console.log("I own a dog");
  15. } else if (pet === "cat") {
  16.   console.log("I own a cat");
  17. } else if (pet === "snake") {
  18.   console.log("I own a snake");
  19. } else if (pet === "parrot") {
  20.   console.log("I own a parrot");
  21. } else {
  22.   console.log("I don't own a pet");
  23. }
  24. for more:http://besturl.link/jRYt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement