Boolean - MDN Web Docs Glossary: Definitions of Web-related terms | MDN (2024)

In computer science, a Boolean is a logical data type that can have only the values true or false.

For example, in JavaScript, Boolean conditionals are often used to decide which sections of code to execute (such as in if statements) or repeat (such as in for loops).

Below is some JavaScript pseudocode (it's not truly executable code) demonstrating this concept.

js

/* JavaScript if statement */if (boolean conditional) { // code to execute if the conditional is true}if (boolean conditional) { console.log("boolean conditional resolved to true");} else { console.log("boolean conditional resolved to false");}/* JavaScript for loop */for (control variable; boolean conditional; counter) { // code to execute repeatedly if the conditional is true}

The Boolean value is named after English mathematician George Boole, who pioneered the field of mathematical logic.

Above is a general introduction. The term Boolean can have more specific meanings depending on the context. It may refer to:

Boolean (JavaScript)
A Boolean in JavaScript is a Primitive that can be either true or false.
Boolean attribute (ARIA)
A boolean attribute in ARIA is an Enumerated that includes true or false in the enumerated list.
Boolean attribute (HTML)
A boolean attribute in HTML is an attribute that represents true or false values. If an HTML tag contains a boolean attribute - no matter the value of that attribute - the attribute is set to true on that element. If an HTML tag does not contain the attribute, the attribute is set to false.

See also

Boolean - MDN Web Docs Glossary: Definitions of Web-related terms | MDN (2024)

FAQs

What does boolean() do in JavaScript? ›

In JavaScript, a boolean value is one that can either be TRUE or FALSE. If you need to know “yes” or “no” about something, then you would want to use the boolean function. It sounds extremely simple, but booleans are used all the time in JavaScript programming, and they are extremely useful.

What is a boolean in HTML? ›

In HTML, some attributes are boolean attributes, which basically means they can be true or false . They are the case, or they are not the case. They compute to one, or they compute to zero. Examples of these attributes include checked , required , disabled and open .

Is boolean true or false? ›

A Boolean value represents a truth value; that is, TRUE or FALSE.

How to pass boolean value in JavaScript function? ›

The operation can be summarized as follows:
  1. Booleans are returned as-is.
  2. undefined turns into false .
  3. null turns into false .
  4. 0 , -0 , and NaN turn into false ; other numbers turn into true .
  5. 0n turns into false ; other BigInts turn into true .
  6. The empty string "" turns into false ; other strings turn into true .
Feb 12, 2024

What is the Boolean type in MDN? ›

The Boolean type represents a logical entity and is inhabited by two values: true and false . Boolean values are usually used for conditional operations, including ternary operators, if...else , while , etc.

What are the 3 Boolean operators in JavaScript and how are they used? ›

Logical Operators
OperatorDescriptionExample
&&and(x < 10 && y > 1) is true
||or(x == 5 || y == 5) is false
!not!(x == y) is true

What is the basic Boolean code? ›

Boolean expressions are written using Boolean operators (AND) &&, (OR)|| and (NOT) !. Example: 1. (x>1) && (x<5) - returns true if both the conditions are true, i.e if the value of 'x' is between 1 and 5.

What is a Boolean in coding? ›

In computing, the term Boolean means a result that can only have one of two possible values: true or false. Boolean logic takes two statements or expressions and applies a logical operator to generate a Boolean value that can be either true or false. To return the result, operators like AND, OR, NOT, etc. are used.

What is a Boolean example? ›

Boolean operator examples

The following are examples of the Boolean operators in programming: >= – True if a number is greater than or equal to another. <= – True if a number is less than or equal to another. == – True if two values are equivalent.

Is false and false true in Boolean? ›

In Boolean logic, false and false is false. False or false is also false. The negation of false is true.

What does 0 mean in Boolean? ›

Boolean Variables and Data Type ( or lack thereof in C )

Zero is used to represent false, and One is used to represent true. For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.

What is the difference between Boolean and bit? ›

'BIT' vs 'BOOLEAN'

While both 'BIT' and 'BOOLEAN' data types can be used to represent similar kinds of data, they are not interchangeable. 'BIT' can hold 1, 0, or NULL, whereas 'BOOLEAN' holds TRUE, FALSE, or NULL.

What is a JavaScript string? ›

JavaScript String is a sequence of characters, typically used to represent text. It is enclosed in single or double quotes and supports various methods for text manipulation.

What is undefined in JS? ›

Simply put, undefined means a variable has been declared but has not yet been assigned a value. undefined is a type by itself (undefined). Unassigned variables are initialized by JavaScript with a default value of undefined.

What is an object in JS? ›

An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method. Objects in JavaScript, just as in many other programming languages, can be compared to objects in real life.

What is the function of a Boolean? ›

In computing, the term Boolean means a result that can only have one of two possible values: true or false. Boolean logic takes two statements or expressions and applies a logical operator to generate a Boolean value that can be either true or false. To return the result, operators like AND, OR, NOT, etc.

What is an example of a Boolean in JavaScript? ›

In JavaScript, booleans are the primitive data types that can either be true or false . For example, const a = true; const b = false; Note: If you wrap true or false in a quote, then they are considered as a string.

Is 0 or 1 a Boolean in JavaScript? ›

0 and 1 are type 'number' but in a Boolean expression, 0 casts to false and 1 casts to true . Since a Boolean expression can only ever yield a Boolean, any expression that is not expressly true or false is evaluated in terms of truthy and falsy. Zero is the only number that evaluates to falsy.

What do Boolean variables do? ›

Boolean variables can either be True or False and are stored as 16-bit (2-byte) values. Boolean variables are displayed as either True or False. Like C, when other numeric data types are converted to Boolean values then a 0 becomes False and any other values become True.

Top Articles
Latest Posts
Article information

Author: Merrill Bechtelar CPA

Last Updated:

Views: 6067

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Merrill Bechtelar CPA

Birthday: 1996-05-19

Address: Apt. 114 873 White Lodge, Libbyfurt, CA 93006

Phone: +5983010455207

Job: Legacy Representative

Hobby: Blacksmithing, Urban exploration, Sudoku, Slacklining, Creative writing, Community, Letterboxing

Introduction: My name is Merrill Bechtelar CPA, I am a clean, agreeable, glorious, magnificent, witty, enchanting, comfortable person who loves writing and wants to share my knowledge and understanding with you.