Is it safe to assume strict comparison in a JavaScript switch statement?



To get out of the confusion regarding strict comparison, try to run the following code snippet in JavaScript −

Example

switch(1) {
   case '1':
      alert('Switch comparison: Not Strict.');
      break;
   case 1:
      alert('Switch comparison: Strict.');
      break;
   default:
      alert(‘Default’);
}
Updated on: 2020-06-24T06:44:25+05:30

143 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements