What is the reason that an empty string evaluates to false in Javascript

前端 未结 1 1628
说谎
说谎 2020-12-12 03:42

Why is it that an empty string evaluates to false in JavaScript. I know Douglas Crockford has spoken quite a bit about truthy and falsy in javascript but this still surprise

相关标签:
1条回答
  • 2020-12-12 03:56

    Because it has nothing in it. An empty string is a false value in many languages. This is standard according to the specification.

    The result is false if the argument is the empty String (its length is zero); otherwise the result is true

    — section 9.2 of Ecma-262

    0 讨论(0)
提交回复
热议问题