Skip to content

Instantly share code, notes, and snippets.

@marcelo-ribeiro
Last active July 30, 2021 03:37
Show Gist options
  • Save marcelo-ribeiro/6e0524b4eba6bebb74bca3a62374d06d to your computer and use it in GitHub Desktop.
Save marcelo-ribeiro/6e0524b4eba6bebb74bca3a62374d06d to your computer and use it in GitHub Desktop.
JS Simple switch shortcut example
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