Skip to content

Instantly share code, notes, and snippets.

@bxt
Created February 26, 2011 15:29
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 bxt/845303 to your computer and use it in GitHub Desktop.
Save bxt/845303 to your computer and use it in GitHub Desktop.
Interesting method to do multi-value-testing in JS
({abc:1,def:1,jkl:1}[xyz])
// nearly the same as:
( xyz=="abc" || xyz=="def" || xyz=="jkl" )
// and....
(function(){switch(pn) {
case "prv":return "previous";
case "nxt":return "next";
}})()
// returns the same as:
(pn=="prv"?"previous":(pn=="nxt"?"next":undefined))
// which returns the same as:
({"prv":"previous","nxt":"next"}[pn])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment