Skip to content

Instantly share code, notes, and snippets.

@marcelo-ribeiro
Last active July 30, 2021 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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