=== Comparison operators === Stricts comparisons should always be used. ==== Rationale ==== When using non-strict operators, JavaScript will coerse one value to match the type of the other. The rules for doing this are complicated and unmemorable (just like PHP's). However, whereas with PHP we only work with one language (and a single implementation of that language), different browsers use different JavaScript engines, which could theoretically handle some things differently. For example, whilst they ''should'' all agree on the coersion rules, they may return different values from DOM elements depending on different situations. E.g. what is the expected type of data-foo vs. data-bar in the example below:
By using explicit type testing, we reduce the possibility for incorrect coersion. In doing so, we also encourage developers to consider the types they are using and how different environments or situations may affect these types. In the following examples, by forcing a strict typing test, we help to enforce the casting to a Number. Without this, the test looks very similar, but because of the lack of inherent type check, the results differ and are unpredictable. ==== Correct ====