true value

The true value means true. It can be used in conditionals with if and elseif to test them for truth, and also with the help of true you can determine the presence of an element or property.

Syntax

javascripttrue;

Example

Let's check if the array contains the letter 'a':

javascriptlet arr = ['a', 'b', 'c', 'd'];
console.log(arr.includes('a'));

The code execution result:

javascripttrue

Example

Let's check if a value of the variable is equal to 1:

javascriptlet num = 1;
console.log(num === 1);

The code execution result:

javascripttrue

Example

Let's check the result of the condition:

javascriptlet test = true;

if(test === true) {
  console.log('+++');
} else {
  console.log('---');
}

The code execution result:

javascript'---'

See also

  • the false value
    that indicates that the element value is false
  • the null value
    that denotes the absence of an object or element
  • the undefined value
    that denotes that the element value is "undefined"