开发者

Javascript: == or ===? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

J开发者_StackOverflow社区avascript === vs == : Does it matter which “equal” operator I use?

Hi, This is my tiny code:

var domains_before_update = storage.getItem('domain_list_original');
    if(domains_before_update==null || domains_before_update=="" )
    { 
           gBrowser.selectedTab = gBrowser.addTab("chrome://filter/content/block_and_redirect_list.html");

    }

Is that correct or should I be using === instead of == ?

Thanks!


=== checks the strict equals (without coercion) that you're used to , where == checks the value [after built-in coercion] equality

but as the other answer(s) noted, strict equality does not work when checking for null, use !variable

same as this post: Difference between == and === in JavaScript

edit: clarified some of the wording thanks to the helpful comments!


In this case, it doesn't matter - and in all cases where it doesn't matter, you should use strict equality or identity, e.g. ===.


Neither.

Use:

if(!domains_before_update)
{

}


For comparisons with null, === is required.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜