Skip to content

true

In JavaScript, true is a reserved word and a literal that represents the logical value for yes, on, or a condition that holds. It’s one of the two values of the boolean type, and false is the other.

Comparison operators, !, in, and instanceof produce true when their test passes, and typeof true returns "boolean". As a reserved word, true can’t name a variable, function, or parameter, and it can’t be reassigned. It still works as a property name, as in { true: 1 }.

A condition doesn’t need to be true itself to pass. Statements like if accept any truthy value. Arithmetic and loose equality convert true to the number 1, but strict equality doesn’t, so true === 1 is false.

JavaScript true Keyword Examples

The true literal is one of the two boolean values, and comparisons produce it too:

Language: JavaScript
> typeof true
'boolean'
> 5 > 3
true

> true === 1
false
> true + 1
2

> const true = "yes";
const true = "yes";
      ^^^^

Uncaught SyntaxError: Unexpected token 'true'

The comparison 5 > 3 evaluates to true. Strict equality treats true and 1 as different values, while the + operator converts true to 1 through type coercion. The last line fails because true is reserved.

JavaScript true Keyword Use Cases

  • Initializing Boolean flags that start switched on
  • Returning the positive result of a check from a predicate function
  • Writing while (true) loops that exit through break or return
  • Enabling settings in configuration objects, such as { once: true }

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 3, 2026