How to use return, return true, and return false in JavaScript?
In JavaScript, the return statement is used to return a value from a function. If no return value is specified, the function will return undefined.
“return true and return false are used to return the boolean values true or false. This is typically used to determine if a function has executed successfully or meets specific conditions. For example:”
function isEven(num) {
if (num % 2 === 0) {
return true;
} else {
return false;
}
}
console.log(isEven(4)); // 输出 true
console.log(isEven(3)); // 输出 false