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

  • SEARCH
  • Home
  • 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 7183095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:54:37+00:00 2026-05-28T17:54:37+00:00

I am a newbie to java script and currently reading John Resig’s Pro javascript

  • 0

I am a newbie to java script and currently reading John Resig’s Pro javascript techniques . While explaining closure he refers to calls like setTimeout("otherFunction()",2000) as instances where new JS developers have problems . I could not understand why this is a problem ? Can some one explain please ?In this http://www.w3schools.com/js/js_timing.asp I am seeing a call like var t=setTimeout("alertMsg()",3000); which looks similar to me .

  • 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-05-28T17:54:38+00:00Added an answer on May 28, 2026 at 5:54 pm

    It’s not “wrong”, it’s just not necessarily “right”, and it’s certainly not recommended.

    The setTimeout() function‘s first parameter can be a string or a function reference / function expression.

    If you pass a string it will be slower because effectively you are doing an eval() which is not recommended. More important than speed though is that the scope in which the code in the string executes may not be what you are expecting (and may not be the same in different browsers).

    By passing a function reference / function expression instead these problems can be avoided.

    The “right” syntax for your example is:

    setTimeout(otherFunction, 2000);
    

    Note there are no parentheses after otherFunction – if there were it would call otherFunction() immediately and pass the return value from that function to setTimeout().

    If you need to pass parameters to your function you can wrap it in an anonymous function:

    setTimeout(function() {
        otherFunction(param1, param2);
    }, 2000);
    

    That may seem kind of clunky compared to setTimeout("otherFunction(param1,param2)", 2000) but again it avoids issues with scope of where otherFunction, param1 and param2 are defined.

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

Sidebar

Related Questions

I am newbie. many of javascript code start with <!-- <script type=text/javascript> <!-- and
I have just started working with nodejs. I am a java script newbie. I
I am newbie in javascript xml data handling. Currently, my ajax call to a
I'm a newbie in XUL & Java-Script programming. I just realized that I was
As a javascript newbie, I am struggling to use a script with a variable
hi i am newbie to javascript.... i want to synchronize scrolling of two select
I'm a total newbie and want to start with php. I know some javascript
Java Newbie here. I have a JFrame that I added to my netbeans project,
I am a newbie to Java Web Application development. So far all I have
I'm a newbie on Java EE and got a problem that I don't understand

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.