Unable to access variable outside of function when invoked as setInterval callback

Hi,
In below code, I defined a function func1.
When func1 is called normally, it works fine.
But, When it is passed into setInterval as a callback, it can’t access variable v1 outside.

In nodejs, both of calling work same.
Is this a bug? Or Is there my mistake?

{{    
    (function() {
        let v1 = 0;
        const func1 = function () {
            console.log(v1);
        } 

        // working when called normally
        func1()


        // not working as a callback.
        // unable to access  v1.
        setInterval(func1, 1000, 'test'); 
    })()
}}

Error message:
image

Hello, there is an issue with accessing outer functions.

1 Like

some issue, any solutions?

Could you please try using appsmith store for a temporary workaround like mentioned in the issue comment here.
Hope this helps in unblocking you for now. @poplee @srrrrrr27

1 Like

Rishabh_Rathod
Thanks. Already i decided to not use setInterval. I will try when i need to use setInterval!!!