Short answer: never. This post looks at five possible exemptions from the rule to always use === and explains why they aren’t.
JavaScript has two operators for determining whether two values are equal [1]:
Prefer intention-revealing code to terse code.Remember: Your code is only written once but likely read many times – make it as easy for readers as possible.
    if (typeof x == "function") {
        ...
    }
However, there are two reasons not to do this:
    > null == null
    true
    > undefined == null
    true
    > false == null
    false
    > 0 == null
    false
Thus, the following if statement checks for either null or undefined.
    if (x == null) {
        ...
    }
However, the increased terseness is offset by such code being less explicit about your intentions: If the check for undefined matters then you might as well put that in writing. Otherwise, if a JavaScript beginner reads your code, they might think you are only checking for null. If an advanced programmer reads your code, they might think that you made an error and meant to write ===.
    if (x === undefined || x === null) {
        ...
    }
If you can afford to be a little sloppy then the above can be abbreviated to
    if (!x) {
        ...
    }
The usual caveat applies: The condition holds if x has either of the following “falsy” values.
    undefined
    null
    false
    0
    ""
    if (x == 123) {
        ...
    }
But why not tell readers of your code that if x isn’t a number, it should be converted to one?
    if (Number(x) === 123) {
        ...
    }
    > function isAbc(x) { return x == "abc" }
    > isAbc("abc")
    true
    > isAbc(new String("abc"))
    true
With ===, you can’t:
    > new String("abc") === "abc"
    false
The left-hand side is an object while the right-hand side is a primitive. Hence, they don’t have the same type and aren’t strictly equal. However, you again should make it a priority to explain to a reader of your code what your intentions are. Given the expression
x == "abc"What do you want to accomplish?
String(x) === "abc"
x.valueOf() === "abc"
    > "abc" + false
    'abcfalse'
    > 3 + true
    4
    > +"73"
    73
There are several counter-arguments to the above hypothesis:
    > !"false"
    false
    > 7 + "3"
    '73'
    > Number("")
    0
        > 2 == false
    false
    > 2 == true
    false
    > Boolean(2)
    true
        function is123Implicit(x) {
        return x == 123;
    }
    > is123Implicit(123)
    true
    > is123Implicit(new Number(123))
    true
    > is123Implicit("123")
    true
        Alternative: Flexibility via an explicit conversion and strict equals.
    function is123Explicit(x) {
        x = Number(x);
        return x === 123;
    }
    > is123Explicit(123)
    true
    > is123Explicit(new Number(123))
    true
    > is123Explicit("123")
    true
        function is123Defensive(x) {
        if (typeof x !== "number") {
            throw new TypeError("Not a number: "+x);
        }
        return x === 123;
    }
        If you want to pass anything but a primitive number to this function, you must perform a conversion first.