Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:29:37+00:00 2026-06-02T22:29:37+00:00

I was under the impression that setInterval(/*some code*/, time) was equivalent to setInterval(function() {

  • 0

I was under the impression that

setInterval("/*some code*/", time)

was equivalent to

setInterval(function() {
   /*some code*/
}, time)

Apparently not! Please compare the following (full HTML):

<pre id=p><script>n=setInterval("for(n+=7,i=k,P='p.\\n';i-=1/k;P+=P[i%2?(i%2*j-j+n/k^j)&1:2])j=k/i;p.innerHTML=P",k=64)</script>

and

<pre id=p><script>n=setInterval(function() { for(n+=7,i=k,P='p.\\n';i-=1/k;P+=P[i%2?(i%2*j-j+n/k^j)&1:2])j=k/i;p.innerHTML=P },k=64)</script>

The two animations (the first being taken from here) are different.

Why are the two constructs not equivalent?

Answer: There are at least three differences

  1. Variable scope
  2. Performance
  3. String character escapes
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:29:38+00:00Added an answer on June 2, 2026 at 10:29 pm

    Those two forms of setInterval are essentially equivalent — but your code isn’t. In the second example you’re double-escaping your newline as \\n, instead of just \n. Try this:

    <pre id=p><script>n=setInterval(function() { for(n+=7,i=k,P='p.\n';i-=1/k;P+=P[i%2?(i%2*j-j+n/k^j)&1:2])j=k/i;p.innerHTML=P },k=64)</script>
    

    And that should be just like what you want.

    The function() form of setInterval is better in a lot of ways — it’s more readable, and as you ran into here, you don’t have to deal with trying to escape strings inside of string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was under the impression that this code #include <windows.h> #include <stdio.h> int WINAPI
I was (and have been for a long time) under the impression that you
I was under impression that in F# the following two lines are supposed to
I was under the impression that not calling Response.Flush would ensure that Connection: Close
I was under the impression that Function Scoped Non-Pod structures are intialized the first
I was under the impression that the format() function of the PHP DateTime class
I was under the impression that if you put a line of code in
I am under the impression that the below code should work asynchronously. However, when
I was under the impression that the css rules in the callback function below
So I was under the impression that rendering designs on the HTML5 canvas would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.