Introduction
In this lab, we will dive into the concept of boolean values in JavaScript. We will explore how to check whether a given value is a boolean primitive or not using the typeof operator. By the end of this lab, you will have a solid understanding of how to identify boolean values in JavaScript.
Checking if a Value is Boolean
To check if a value is a boolean primitive in JavaScript, use the typeof operator with the === comparison operator.
const isBoolean = (val) => typeof val === "boolean";
Here's an example of how to use isBoolean() function to check if a value is boolean:
isBoolean(null); // returns false
isBoolean(false); // returns true
To start practicing coding, open the Terminal/SSH and type node.
Summary
Congratulations! You have completed the Value Is Boolean lab. You can practice more labs in LabEx to improve your skills.