The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript problem with switch Reply To: problem with switch


There shouldn’t be a semi-colon after the switch:

Also note that, because of semicolon insertion, you may still run into silent failures with your brackets on the left:

whatever ()
    this doesn't always work

whatever (){
    always put them on the right

This is a personal preference and never causes any real problems except in JavaScript.

I would also highly recommend always including a default statement in your switches (even if it simply breaks without doing anything).