Glitch code editor glitch... halp

I think there is a glitch in the code editor.

// So, in the first place, this works perfectly:
let c;
switch(stuff) {
  case "something":
    c = something;
  break;
  case "something_else":
    let c = something;
  break;
  default: something();
}


// While this pulls up errors for some reason... even tho its perfectly good:
switch(stuff) {
  case "something":
    let c = something;
  break;
  case "something_else":
    let c = something;
  break;
  default: something();
}


// Also... this also works for some reason even though its COMPLETELY WRONG AF
// (I ran it and it brought up an error):
switch(stuff) {
  case "something":
    let c = something;
  break;
  case "something_else":
    c = something;
  break;
  default: something();
}

Since variables in javascript are block scoped, and a switch statement is the block, js will think the variable has already been defined, what you can do to fix this is wrap the cases in a function.

1 Like

I had that idea but I thought it was kinda unnecessary…
Thanks for the help anyways!