-1

[enter image description here][1]testing truthy value to false

What am i missing here..

how can a truthy value campared to false yields true ? something wrong in the code or is that a bug? Can someone please explain that ?

  • 2
    [Please do not upload images of code/data/errors when asking a question.](//meta.stackoverflow.com/q/285551) – CBroe Jun 29 '22 at 11:03
  • 2
    which `truthy value` is being `campared to false` in that pretty image that you should post as code here? – Bravo Jun 29 '22 at 11:03
  • 1
    `spaces == false` is not what you use to determine falsiness. `!!spaces`/`Boolean(spaces)` is. – Bergi Jun 29 '22 at 11:03
  • I dont know why everybody only emptyString variable. removing it from code. uploading new image. – Jatin Johny Jun 29 '22 at 11:06
  • 1
    @JatinJohny No, don't upload a new image. Add it as code/text. See the post linked by CBroe in the first comment. – Ivar Jun 29 '22 at 11:07
  • Sorry, I am new here, i dont know how to post code snippet from chrome's console here. That's why posted screenshot – Jatin Johny Jun 29 '22 at 11:12
  • @Bergi, This may not be the correct way. But why spaces == false returns true ? – Jatin Johny Jun 29 '22 at 11:16
  • See [I've been told to create a "runnable" example with "Stack Snippets". How do I do that?](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) You can add `console.log()`'s to your snippet to run/log the expressions. But that being said, I think the questions linked in the blue box above your question should already provide the answer you are looking for. – Ivar Jun 29 '22 at 11:16
  • 1
    @JatinJohny Specifically see [this answer](https://stackoverflow.com/a/33705786/479156). – Ivar Jun 29 '22 at 11:17

1 Answers1

-1

Because you use lose comparison == instead of strict comparison ===, so your emptyString is converted to boolean to be comparable against false

Justinas
  • 41,402
  • 5
  • 66
  • 96