How to get return value from switch statement?

That’s because when you’re putting that into the Chrome console, you’re short-circuiting it. It’s just printing ‘OK’ because it’s reaching the default case, not actually returning something.

If you want something returned, stick it in a function, and return the ‘OK’ from in the default case.

function switchResult(a){
    switch(a){
        default: 
            return "OK";
    }
}

var a = switchResult(3);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)