WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Booleans


A JavaScript Boolean speaks to one of two qualities: true or false.


Boolean Values

Very frequently, in programming, you will require an information type that can just have one of two qualities, like

  • YES/NO
  • ON/OFF
  • TRUE/FALSE

For this, JavaScript has a Boolean information type. It can as it were take the qualities true or false.


The Boolean() Function

You can utilize the Boolean() capacity to see whether an articulation (or a variable) is true:

Example

Boolean(10 > 9)       /returns genuine
Try it yourself »

Or even easier:

Example

(10 > 9)             /likewise returns true
10 > 9               /likewise returns genuine
Try it yourself »

Comparisons and Conditions

The part JS Comparisons gives a full outline of examination operators.

The part JS Conditions gives a full outline of restrictive statements.

Here are some examples:

Operator Description Example
== equal to if (day == "Monday")
> greater than if (pay > 9000)
< less than if (age < 18)

Everything With a "Real" Value is True

Examples

100

3.14

- 15

"Hello"

"false"

7 + 1 + 3.14

5 < 6
Try it yourself »

Everything Without a "Real" is False

The Boolean estimation of 0 (zero) is false:

var x = 0;
Boolean(x);      /returns false
Try it yourself »

The Boolean estimation of -0 (short zero) is false:

var x = - 0;
Boolean(x);      /returns false
Try it yourself »

The Boolean estimation of "" (empty string) is false:

var x = "";
Boolean(x);      /returns false
Try it yourself »

The Boolean estimation of undefined is false:

var x;
Boolean(x);      /returns false
Try it yourself »

The Boolean estimation of null is false:

var x = null;
Boolean(x);      /returns false
Try it yourself »

The Boolean estimation of false is (you gotten it) false:

var x = false;
Boolean(x);      /returns false
Try it yourself »

The Boolean estimation of NaN is false:

var x = 10/"H";
Boolean(x);      /returns false
Try it yourself »

Boolean Properties and Methods

Primitive qualities, similar to genuine and false, can't have properties or then again techniques (since they are not objects).

But with JavaScript, techniques and properties are additionally accessible to crude qualities, in light of the fact that JavaScript treats crude qualities as items when executing strategies and properties.