I have a javascript function as shown below.
function checkEven(number){
return(number % 2 == 0 ? true : false)
setTimeout(checkEven(number), 2000)
}
I want to call checkEven function within every 2 seconds. but it is not working.
But then I tried the following code. It working fine and print method gets called in every 2 seconds.
function print(){
console.log(new Date());
setTimeout(print, 2000)
}
I want to understand why the first code didn't work. I need help with this.