Skip to content

Instantly share code, notes, and snippets.

@adccb
Created March 20, 2018 16:07
Show Gist options
  • Save adccb/b8a42d2978c57d6842d2a0103dadd2e2 to your computer and use it in GitHub Desktop.
Save adccb/b8a42d2978c57d6842d2a0103dadd2e2 to your computer and use it in GitHub Desktop.
switch nonsense
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