1

Consider the following code:

// Checking parities
switch(queueingSystem.Priority) {
    case 1: 
         FetchGridElements();
         break;
    case 1: 
         BindToControls(this, document.getElementsByClassName("grid-controls"));
         break;
    default:
         return false;
}

Is JavaScript internally testing value as well as type against each case, equivalent to:

queueingSystem.Priority === 1

Or

queueingSystem.Priority == 1
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
Annie
  • 3,090
  • 9
  • 36
  • 74

2 Answers2

4

It checks the strict equality === as is demonstrated by this code :

switch (1) {
  case "1":
     console.log('ok');
     break;
  default :
     console.log('nok');
}

which logs nok.

It's defined in the ECMAScript specification :

If input is equal to clauseSelector as defined by the === operator, then

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
2

Types are compared:

queueingSystem.Priority === 1
jtomaszk
  • 9,223
  • 2
  • 28
  • 40