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 associated value of true. We can use this to cast a variable to trueor false using the double bang operator.
Let’s dive deep into what it is and how it works.
The !
in JavaScript, also called bang, is the logical “not” operator. If you place this operator in front of a _boolean _value, it will reverse the value, returning the opposite.
!true // returns false
!false // returns true
isTrue = true // variable which is boolean
!isTrue // returns false
If the single bang returns the opposite _boolean _value, imagine what double-bang would return?
The associated boolean value. In other words, true or false according to whether it is truthy or falsy values.
#web-development #programming #javascript