Every value has truth or false values in JavaScript. For example, a null value has an associated boolean value of false. Similarly 34 has an associ...
For further actions, you may consider blocking this person and/or reporting abuse
This is very well explained. You can also call this the double NOT operator if you'd like.
While
Boolean(someValue)
the same things as!!someValue
, using the double not operator is shorter to write and a tiny bit faster. The speed increase is nothing meaningful, but interesting nonetheless.Benchmark I ran in case you want to see for yourself:
This is interesting. Never thought about
Boolean()
. Thank you.It isn't a double bang operator, it is using the ! operator twice. Also, since - as you rightly state - values already have truthy and falsey-ness, it is largely pointless to use this unless you really, really need a pure boolean (perhaps for building some JSON to send somewhere on another system that requires the correct type)
That rocks, I remember it as "Bang Bang, you're a boolean now".
Bang Bang, you're a Boolean now
I totally had forgotten about this. :)
I feel like they article made this whole concept really complicated. It's actually simple, What is
!!
?. It's the same asCoerce to boolean
. It would do the same as a methodConvert.toBoolean(value)
where value istruthy
orfalsy
and the result istrue
orfalse
.You need this because some parameters are expected to be
true
orfalse
and nottruthy
andfalsy
.Boolean(value)
doesn't actually coerce a value to a boolean, it's unfortunately less useful than that. And so using!!
(the double NOT) is a great way to coerce a value to a boolean.Cool!! I didn't know 👍
👍
what i learned that if a value is true or false.
by default it does not return anything if it is not explicitly set with true or false boolean . that means by default it returns the value only.
if single bang (!) is added before the value, it returns false.
if double bang (!!) is added before the value, it returns true.
am i correct ?
@geometry dash lite Instead of using a double bang operator, it is twice using the! operator. As you properly point out, values already have truthiness and falseness, so using this is practically pointless unless you really, truly need a pure boolean (maybe for making some JSON to transmit someplace on another system that has the correct type)
Good stuff!
❤️ clear 👍👍
Hey Sanchithasr! I'm stuck in a problem in React JS can you please help asap
Hey. I have not worked on React much. Please post the problem. Someone might be able to help out. :)