-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>
2
  • 5
    That's because you're using strings, not actual booleans... Commented Aug 7, 2013 at 13:45
  • The string "False" is truthy. JavaScript isn't THAT loosely typed. Commented Aug 7, 2013 at 14:26

2 Answers 2

5

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

var test = false;
alert(!test); 
Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.