title: Converting truthy/falsy values to boolean tip-number: 30 tip-username: hakhag tip-username-profile: https://github.com/hakhag tip-tldr: Logical operators are a core part of JavaScript, here you can see a a way you always get a true or false no matter what was given to it.
- /en/converting-truthy-falsy-values-to-boolean/
You can convert a truthy or falsy value to true boolean with the !!
operator.
!!''; // false
!!0; // false
!!null; // false
!!undefined; // false
!!NaN; // false
!!'hello'; // true
!!1; // true
!!{}; // true
!![]; // true