Skip to content

Instantly share code, notes, and snippets.

@schabibi1
Created February 12, 2019 22:01
Show Gist options
  • Save schabibi1/1138483658b1f6f262f4cc370f8a3afc to your computer and use it in GitHub Desktop.
Save schabibi1/1138483658b1f6f262f4cc370f8a3afc to your computer and use it in GitHub Desktop.
JavaScript: Is Fallthrough From Switch Statement A Troublemaker?
let description = {
"Yoda" : "Jedi",
"Anakin" : "Jedi",
"Obi-One" : "Jedi",
"Luke" : "Jedi",
"Ray" : "Jedi",
"Finn" : "Jedi",
"Kylo Ren" : "Jedi",
"Chewbacca" : "Wookiee",
"R2-D2" : "Astromech droid",
"Default" : "Unknown character!"
}
let result = description[name] || description["Chewbacca"];
console.log(result); // Wookiee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment