Can someone explain why my code not returning booWho(1) false

function booWho(bool) {
  if(bool == true || bool == false) {
    bool = true;
  } else {
    bool = false;
  }
  return bool;
}
booWho(1);

This is because you are using an if statement that is setting the parameter to true every time.

if(bool == true || bool == false) translated in english is: If the value of bool is loosely equal to true OR if the value of bool is loosely equal to false then set the value of bool to true.

The else never gets reached because the first if statement passes whether bool is true or false.

Loosely equals in JS is when you use == instead of ===. What this does is ‘coerces’ values such as 1 to true and 0 to false. See coercion for more information on this.

Hope this answers your question. :slight_smile:

1 Like

but its not returning false value on boWhoo(1). its working fine on other false value.

booWho(1) is passing in 1 which is loosely equal == to true.
If you pass in any other value besides 1, 0, true, or false then it will return false

If you changed the loose equals == to strict equals ===, then it would no longer return to the 1 and 0 as true.

See coercion: https://www.freecodecamp.org/news/js-type-coercion-explained-27ba3d9a2839/

1 Like

Thank you very much for explain error, i really appreciate it.