javascript switch(true)

It works for me:

var a = 0, b = true;
    
switch(true) {
    case a:
        console.log('a');
        break;
    case b:
        console.log('b');
        break;
}

However, the case labels must be equal to true, not just implicitly true.
Also, only the first case that evaluates to true will execute.

Leave a Comment