0

In Javascript, is

return (someBooleanValue == true)

necessarily always the same as

return someBooleanValue

?

BVernon
  • 3,205
  • 5
  • 28
  • 64
  • No, try e.g. `[1]` or [any of these](http://stackoverflow.com/search?q=%22==+true%22+javascript) – Bergi Oct 29 '14 at 19:40
  • http://stackoverflow.com/questions/7615214/in-javascript-why-is-0-equal-to-false-but-not-false-by-itself – epascarello Oct 29 '14 at 19:41
  • 1
    What is `someBooleanValue`? Are we assuming it *is* a boolean value? Can it ever be anything else? – gen_Eric Oct 29 '14 at 19:41
  • 1
    @RocketHazmat Yes, I was trying to convey that it is always a Boolean value by the way I named it but I guess I should have explicitly mentioned that. – BVernon Oct 29 '14 at 19:43
  • @BVernon: I just wanted to make sure, even though it looked obvious. – gen_Eric Oct 29 '14 at 19:45

2 Answers2

1

Iff someBooleanValue is a boolean value, then yes. For any other object/value, then no.

Ryan Nigro
  • 4,389
  • 2
  • 17
  • 23
  • Well, there are many objects that would behave like Boolean objects? – Bergi Oct 29 '14 at 19:45
  • 1
    Why does this have a downvote? The OP said (in a comment) that he is working with a boolean, hence `someBooleanValue`. – gen_Eric Oct 29 '14 at 19:45
  • The question was: "necessarily always the same as". Abstract other types which behave like Boolean objects seems out of scope to me. – Ryan Nigro Oct 29 '14 at 19:46
  • 1
    @RocketHazmat: Not my downvote (I'm still considering it), but this answer talks about `Boolean` *objects*, not *boolean values*. – Bergi Oct 29 '14 at 19:48
1

If you assume that typeof someBooleanValue is 'boolean', then Yes these are equivalent (by pure boolean logic).

For everything else, they are not.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375