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

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


Take a look at ECMA 262, section 12.11, the second algorithm, 4.c.

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


http://qfox.nl/notes/110 answers your question. (This guy knows a lot about the nitty gritty of JavaScript)

Switches in Javascript use strict type checking (===). So you never have to worry about coercion, which prevents a few wtfjs :). If on the other hand you were counting on coercion, tough luck because you can't force it.