JavaScript Boolean Data Type Explained

JavaScript Boolean Data Type Explained

This tutorial explains how boolean data type and Boolean object works in JavaScript. The boolean data type is a common programming language data type that only has two values: true and false. To declare a boolean variable using JavaScript, you just need to assign either true or false as its value.

This tutorial explains how boolean data type and Boolean object works in JavaScript

The boolean data type is a common programming language data type that only has two values: true and false. To declare a boolean variable using JavaScript, you just need to assign either true or false as its value:

const isLoading = true;
const isVisible = false;
console.log(typeof isLoading); // "boolean"
console.log(typeof isVisible); // "boolean"

A boolean variable is usually prefixed with a linking verb like “is”, “can”, or “has”. The boolean values are commonly used to control the flow of your program with the help of conditional statements as in the code below:

if (isLoading) {
  alert("The application is still loading...");
} else {
  alert("The application has finished loading!");
}

You will also get boolean values out of comparison operators like equal to ===, greater than >, and less than < as in the following example:

const isEqual = 3 === 3;
console.log(isEqual); // true
console.log(typeof isEqual); // "boolean"

const isHigher = 9 > 4;
console.log(isHigher); // true
console.log(typeof isHigher); // "boolean"

const isLower = 12 < 4;
console.log(isLower); // false
console.log(typeof isLower); // "boolean"

While the boolean data type is primitive, the Boolean with the capital “B” is an object in JavaScript. Let’s learn the differences between them next.

javascript

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

Hire dedicated JavaScript Developers who are proficient in AngularJS, ReactJS, NodeJS, & VueJS frameworks. Get flexible hiring models as per your business requirements.

What is JavaScript - Stackfindover - Blog

What is PHP: - Who invented PHP, how it works, answers to all such questions about PHP, and much other information, you are going to

JavaScript Shopping Cart - Javascript Project for Beginners

JavaScript Shopping Cart - javascript shopping cart tutorial for beginnersBuy me a coffee 🍺 https://www.paypal.com/paypalme/ziddahSource Code: https://bit....

The essential JavaScript concepts that you should understand

The essential JavaScript concepts that you should understand - For successful developing and to pass a work interview

JavaScript compound assignment operators

We use assignment operator in JavaScript to store values in a variable. Read more...