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 8613357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:51:23+00:00 2026-06-12T04:51:23+00:00

My question is basically an extension to this one: var functionName = function() {}

  • 0

My question is basically an extension to this one:
var functionName = function() {} vs function functionName() {}.
I’ve read through all the answers, but I think I’m still missing the answer to this question:

Why does the type of function declaration matter for jQuery’s onComplete event and the native setInterval method? Moreover, why does it matter for these, but not for the normal addEventListener?

Example with onComplete events (assuming blinkOn() is called):

//like this the onComplete event works normally and the functions call eachother
function blinkOn() { $blink.fadeIn( 500, blinkOff ); }
function blinkOff() { $blink.fadeOut( 500, blinkOn ); }

//like this blinkOff won't be called after the fadeIn
function blinkOn() { $blink.fadeIn( 500, blinkOff ); }
var blinkOff = function() { $blink.fadeOut( 500, blinkOn ); };

Example with setInterval:

//works fine
var timer = setInterval( onTimer, 700);
function onTimer() { ... }

//won't work
var timer = setInterval( onTimer, 700);
var onTimer = function() { ... }

The reason I’d like to know is because I want consistency in my code. If the only way to get that is just using function a() { ... }, that’s okay. But I think var a = function() { ... } is more clear in defining scope. And I’m just really curious.

  • 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-12T04:51:24+00:00Added an answer on June 12, 2026 at 4:51 am

    If you were to define your function above where your calls to the function are, you’d have no issues.

    var toggleLight = function () { light = !light; };

    setInterval(toggleLight, 500);

    Your problem is that you’re trying to access things which don’t exist yet.

    It’s the exact same thing as trying to do this:

    var c = a + b,
    
        a = 12,
        b = 3;
    

    When the program hits c, a and b don’t exist.

    Think of this as happening in three steps, for every single function:

    var a = 12,
        b = 3,
        c = add(a, b);
    
    function add (a, b) { return a + b; }
    

    STEP 1.
    The engine grabs the named function add and works out what it does (defines all named-functions first).

    STEP 2.
    The engine locates all variables in the function and sets them to undefined:

    var a = undefined,
        b = undefined,
        c = undefined;
    
    function add(a, b) { return a + b; }
    

    STEP 3.
    The engine initializes all variables in order.

    // 3.1
    var a = 12,
        b = undefined,
        c = undefined;
    
    
    // 3.2
    var a = 12,
        b = 3,
        c = undefined;
    
    // 3.3
    var a = 12,
        b = 3,
        c = add(a, b); // = return a + b = 15
    

    So doing something like this:

    callFunction(myFunc);
    var myFunc = function () {};
    

    Is equal to this:

    var myFunc = undefined;
    callFunction(myFunc);
    myFunc = function () {};
    

    Solution:

    Separate your implementation from your action.
    Make sure everything is defined before you call anything.

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

Sidebar

Related Questions

this question is a extension of one made in Best Solution Architecture , basically
Hello every one this is basically extension to my previous question. i have write
Basically my question is the exact same one as this: Simple client/server, TCP/IP encrypting
This question is basically an extension of my previous question . I asked the
This is an extension question of PHP pass in $this to function outside class
I can provide more detail if necessary, but my question is basically thus: If
Today I stumbled upon this thread: http://www.mathworks.com/matlabcentral/newsreader/view_thread/112560 The question is basically how to make
This question is related to another question I asked Basically, I have 2 horizontally
Basically this is a question how to access local scope handler. I trying to
I asked this question before but didn't make it clear that I meant in

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.