Introduction
In this post, we'll learn what the !!
operator does in JavaScript.
The !!
operator in JavaScript
The !!
converts an Object
to boolean
. This works similarly to Boolean(object)
. If the object is falsey (e.g., 0, null, undefined, etc.), it would be false, otherwise, true.
The !!
converts a non-boolean to an inverted boolean (for instance, !5 would be false since 5 is a non-false value in JavaScript), then boolean-inverts that so you get the original value as a boolean (so !!5 would be true).
Conclusion
In this article, we described what the !!
operator means in JavaScript, and how to use it.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}