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
true;
Example
Let's check if the array contains
the letter 'a':
let arr = ['a', 'b', 'c', 'd'];
console.log(arr.includes('a'));
The code execution result:
true
Example
Let's check if a value of the
variable is equal to 1:
let num = 1;
console.log(num === 1);
The code execution result:
true
Example
Let's check the result of the condition:
let test = true;
if(test === true) {
console.log('+++');
} else {
console.log('---');
}
The code execution result:
'---'