What will be printed to the console as a result?
 var a;
switch(a)
{
    case 0: 
        alert('0'); 
        break;
    case null: 
        alert('null'); 
        break;
    case undefined: 
        alert('undefined'); 
        break;
    default:
        alert('something else');
}
 
Explanation
Switch acts like a big if / else if / else chain. Checks a value against a list of cases, and executes the first case that is true. Example:

    function printValue(value){
        switch (value) {
            case 1:
                console.log('number one');
                break;
            case 2:
                console.log('second one');
                break;
            default :
                console.log('third one');
        }
    }
    printValue(1); // will print 'number one'
    printValue(2); // will print 'second one'
    printValue(3); // will print default value
//The default keyword specifies the code to run if there is no case match

@misterds thanks! fixed

2018 Jan 30, 6:26:50 PM

in the console is showing undefined but is pop the box with the "something else ", please be more specified the question

2017 Dec 15, 8:49:21 PM

@mrameshkumarc21 'something else' is an `alert`, that you can see in a pop-up. But in console will be 'undefined'

2017 Dec 6, 10:08:41 AM

i just pasted this code in console (chrome browser), answer is "something else"

2017 Oct 11, 5:50:24 AM

@alexdykyi62, we have checked answer! and the right answer still 'undefined'

2016 Jan 20, 5:16:05 PM

@iliana000, fixed!)

2016 Jan 20, 5:15:20 PM

An unreadable code

2016 Jan 15, 7:26:19 PM

Right answer "something else" !

2016 Jan 14, 3:03:09 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes