Shorthand checking for true in JavaScript
Let's say we want to know if the variable
test is equal to the value true.
In this case, the construction if
can be written as:
javascriptlet test = true;
if (test == true) {
console.log('+++');
} else {
console.log('---');
}
In programming, such checks are needed
very often, so there is a more elegant
shorthand for them: instead of if
(test == true), you can simply write
if (test).
Let's rewrite our code in shortened form:
javascriptlet test = true;
if (test) {
console.log('+++');
} else {
console.log('---');
}
Задание 1
Rewrite the following code using the shortened form:
javascriptlet test = true;
if (test === true) {
console.log('+++');
} else {
console.log('---');
}