-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,593
  • 30
  • 104
  • 210

2 Answers2

5

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

var test = false;
alert(!test); 
tymeJV
  • 103,943
  • 14
  • 161
  • 157
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,932
  • 7
  • 61
  • 93