Forum Moderators: open

Message Too Old, No Replies

setInterval() warning of implied eval

         

csdude55

5:56 am on Nov 17, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've always used setTimeout and setInterval like this:

setInterval("console.log('one')", 5000);

In testing with JSFiddle, though, I see that it has a warning:

Implied eval. Consider passing a function instead of a string.

I tested and found that this works fine and removes the warning:

setInterval(() => console.log('one'), 5000);

Is there a reason to go through all of my setTimeout and setInterval to make this change, or is this really just a warning that I can completely ignore?

robzilla

10:46 am on Nov 17, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



eval is okay-ish if there's no risk of hijacking. Much slower, though, and I know you're sensitive to that ;-)