0

Can someone explain me what are the difference between these 2 lines?

setInterval(() => $('#mainDiv').load(getData()), seconds * 1000);
setInterval("$('#mainDiv').load(getData())", seconds * 1000);

result is the same, but I'm wondering is there any difference

  • 1
    Does this answer your question? [Difference between arguments in setInterval calls](https://stackoverflow.com/questions/4719758/difference-between-arguments-in-setinterval-calls) or [Is there ever a good reason to pass a string to setTimeout?](https://stackoverflow.com/questions/6081560/is-there-ever-a-good-reason-to-pass-a-string-to-settimeout) – Ivar Nov 18 '20 at 14:52
  • 2
    First one passes an anonymous function to be triggered, whereas the second one passes a string to be evaluated and executed. Try to avoid the second one. – JavaScript Nov 18 '20 at 14:52
  • @JavaScript your response is right (for me), but why you dont put it as an answer ? – Ahmad MOUSSA Nov 18 '20 at 15:01
  • Most likely because this is quite a common asked question which already has a lot of duplicates – Rory McCrossan Nov 18 '20 at 15:06
  • It is a duplicate and my comment does not provide any real explanation/value. Was just too lazy to search one. – JavaScript Nov 18 '20 at 15:06

0 Answers0