convert object to boolean javascript

Solutions on MaxInterview for convert object to boolean javascript by the best coders in the world

showing results for - "convert object to boolean javascript"
Lukas
05 May 2017
1// bool will be false if object is null, false, 0, etc.
2// bool will be true if object is an array, object, non-zero number, etc.
3
4// method 1
5let bool = !!object;
6
7// method 2
8let bool = Boolean(object);
Marisa
22 Jul 2016
1!!"" // false
2!!0 // false
3!!null // false
4!!undefined // false
5!!NaN // false
6
7!!"hello" // true
8!!1 // true
9!!{} // true
10!![] // true
11