Last active
July 30, 2021 03:37
-
-
Save marcelo-ribeiro/6e0524b4eba6bebb74bca3a62374d06d to your computer and use it in GitHub Desktop.
JS Simple switch shortcut example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getColor = () => "red"; | |
const color = getColor(); | |
({ | |
red: () => alert("Vermelho"), | |
blue: () => alert("Azul") | |
}[color]?.()); | |
// OR | |
const colors = { | |
red: "Vermelho", | |
blue: "Azul", | |
default: "Indefinida" | |
}; | |
alert(cars[color] || cars["default"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment