10.
What is the output of the following code?
function isPrime(number) {
if (number <= 1) return false;
for (let i = 2; i <= Math.sqrt(number); i++) {
if (number % i === 0) return false;
}
return true;
}
console.log(isPrime(7));
Error
undefined
false
true
Correct: D
The isPrime function checks if a given number is a prime number. In this code, isPrime(7) is called, which returns true because 7 is a prime number. The function returns true if the number is greater than 1 and not divisible by any number other than 1 and itself.