Created
September 20, 2021 08:15
-
-
Save zaceno/885aad30b03e193cd85d4260a277d4c6 to your computer and use it in GitHub Desktop.
switch-vs-nested-ternary.js
This file contains hidden or 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
//COMPARE: | |
let page; | |
switch (hash) { | |
case '#about': | |
page = 'about' | |
break; | |
case '#photos': | |
page = 'photos' | |
break; | |
case '#blog' | |
page = 'blog' | |
break; | |
default: | |
page = 'home' | |
} | |
//TO: | |
let page = | |
hash === '#about' ? 'about | |
: hash === '#photos' ? 'photos' | |
: hash === '#blog' ? 'blog' | |
: 'home' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment