-
Aug 27th, 2014, 02:53 PM
#1
[Javascript] Change boolean value
I'm wanting to change the value of a Boolean variable in JavaScript to opposite of what it currently is. In VB.Net, I'm able to do this:
Code:
Dim bool As Boolean = True
bool = Not bool
How can I do the same thing in JavaScript without using a conditional statement?
-
Aug 27th, 2014, 04:45 PM
#2
Re: [Javascript] Change boolean value
-
Aug 27th, 2014, 05:13 PM
#3
Re: [Javascript] Change boolean value
Oh. Simple enough, thanks.
-
Aug 27th, 2014, 05:24 PM
#4
Re: [Javascript] Change boolean value
Now I am thinking it's
[edit] nevermind - that is the BITWISE NOT [/edit]
-
Aug 27th, 2014, 06:55 PM
#5
Re: [Javascript] Change boolean value
As szlamany said, it's a single !. You can also use a double !! (double logical-NOT) to convert truthy/falsey values to strict boolean.
-
Aug 27th, 2014, 06:57 PM
#6
Re: [Javascript] Change boolean value
The double bitwise NOT is also pretty cool.
Last edited by tr333; Aug 27th, 2014 at 07:02 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|