Can a switch case test if a value meets a complex condition instead of just equality comparison?
21:35 14 Aug 2011

How can I do something like this with a switch statement:

String.prototype.startsWith = function( str ){
    return ( this.indexOf( str ) === 0 );
}

switch( myVar ) {
    case myVar.startsWith( 'product' ):
        // do something 
        break;
}

This is the equivalent of:

if ( myVar.startsWith( 'product' )) {}
javascript switch-statement