Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 13
    Bad idea. You'll get true if strVar is accidentally assigned 0. Commented Sep 30, 2008 at 19:21
  • 5
    I agree that making your intention clear is more important than any micro-optimizations other methods might yield, but using the strict comparison operator === would be better. It only returns true if strVar is an empty string. Commented Jun 13, 2015 at 17:52
  • The check fails if undefined. So if(str) works better Commented Dec 27, 2015 at 13:57
  • 4
    @ValentinHeinitz if str were assigned a falsey value of 0 or "0", if(str) would falsely report true. The best approach is if(str === ""). It's simple and it will never fail. Commented Jan 28, 2016 at 22:02
  • 1
    Which equals operator (== vs ===) should be used in JavaScript comparisons? Commented Jan 18, 2018 at 21:19