I'm trying to get the flag value in the console.log(). But when I equalize flag to entry.isIntersecting it returns undefined. In the commented console.log function I get the correct result of flag. I tried async method too but it gave same result.
let flag = false;
const observer = new IntersectionObserver(function(entries, observer){
entries.forEach(entry => {
flag = entry.isIntersecting
/*console.log(flag)*/
return flag
})
}, options)
console.log(flag)