-7

I am using not equal sign to convert false to true but it is always giving false. I have tried it with 0 and 1 which is working fine. Also when I am changing value "False" to "true" then it is also working but problem is with "false" only.

<script type="text/javascript">
var test= "False";
alert(!test)
</script>
Jitender
  • 7,057
  • 25
  • 92
  • 193

2 Answers2

5

You are assigning the string "False", assign the boolean false

var test = false;
alert(!test); 
tymeJV
  • 102,126
  • 13
  • 159
  • 155
0

If you put quotes around your boolean, you actually make a string of it. You should do it like this instead:

<script type="text/javascript">
    var test = false;
    alert(!test)
</script>
ndequeker
  • 7,702
  • 7
  • 58
  • 93