Value Is Boolean

Beginner

This tutorial is from open-source community. Access the source code

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.

This is a Guided Lab, which provides step-by-step instructions to help you learn and practice. Follow the instructions carefully to complete each step and gain hands-on experience. Historical data shows that this is a beginner level lab with a 100% completion rate. It has received a 100% positive review rate from learners.

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.