Created
March 20, 2018 16:07
-
-
Save adccb/b8a42d2978c57d6842d2a0103dadd2e2 to your computer and use it in GitHub Desktop.
switch nonsense
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
const someVar = 'foo' | |
// the bad way | |
switch(someVar) { | |
case foo: | |
const response = 'someVar is foo!' | |
break | |
case bar: | |
const response = 'someVar is bar!' // errors, 'assigning to constant variable response' | |
break | |
default: | |
const response = 'idfk' | |
} | |
// the good-ish way? i guess? | |
switch(someVar) { | |
case foo: { | |
const response = 'someVar is foo!' | |
} | |
case bar: { | |
const response = 'someVar is bar!' | |
} | |
default: { | |
const response = 'idfk' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment