Answers for "convert object to boolean javascript"

1

convert object to boolean javascript

// bool will be false if object is null, false, 0, etc.
// bool will be true if object is an array, object, non-zero number, etc.

// method 1
let bool = !!object;

// method 2
let bool = Boolean(object);
Posted by: Guest on June-13-2021
1

js convert truthy

!!"" // false
!!0 // false
!!null // false
!!undefined // false
!!NaN // false

!!"hello" // true
!!1 // true
!!{} // true
!![] // true
Posted by: Guest on November-17-2020

Code answers related to "convert object to boolean javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language