DEV Community

Randy Rivera
Randy Rivera

Posted on • Edited on

Is It A Boolean?

  • Check if a value is classified as a boolean primitive. Return true or false.
  • Boolean primitives are true and false.
  • Hint: This program is very simple, the trick is to understand what a boolean primitive is. The programs requires a true or false answer.
  1. You will need to check for the type of the parameter to see if it is a boolean.

2.To check for the type of a parameter, you can use typeof.

3.Since you must return true or false you can use if statements or just have it return the boolean used for the if statement.

function booWho(bool) {
  return bool;
}

booWho(null);
Enter fullscreen mode Exit fullscreen mode
  • Answer:


function booWho(bool) {
  if (typeof bool === "boolean") {
    return true;
  }
  return false;
}

console.log(booWho(null)); // will display false
Enter fullscreen mode Exit fullscreen mode

Top comments (0)