Problem with understanding boolean

result true;

please someone tell why it’s printing true. I don’t even comparing it with anything

Boolean() convert anything to true or false.

A number is a truthy value so it prints true, an array is truthy value so it will give true

Values that are falsy (and so that would give false): empty string "", zero 0, undefined, null, NaN

1 Like
function findBoolean(num){
   let x = num;
   if(x == true || x == false){
result true;
result false;

So, This is my whole code. please tell me why when I use 1 it’s printing true but when i type array it printing false?

Neither of those is a Boolean. If you write == there is type coercion which works differently depending on the values involved, in this case 1 is being coerced to a Boolean, an array is usually coerced to a string. Use instead === strict equality if you want to see if something is a Boolean or not