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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:06:51+00:00 2026-06-06T15:06:51+00:00

I have a worked on a couple different projects and I have seen two

  • 0

I have a worked on a couple different projects and I have seen two different ways of creating jQuery/JavaScript functions.

The first:

function testFunction(){

};

The second:

var testFunction = function (){

};

Is there a difference between these?

  • 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-06T15:06:53+00:00Added an answer on June 6, 2026 at 3:06 pm

    The main difference is the first one (a function declaration) is hoisted to the top of the scope in which it is declared, whereas the second one (a function expression) is not.

    This is the reason you are able to call a function that has been declared after you call it:

    testFunction();
    function testFunction() {}
    

    You can’t do that with a function expression, since the assignment happens in-place:

    testFunction();
    var testFunction = function() {}; //TypeError
    

    There is also a third form (a named function expression):

    var testFunction = function myFunc() {};
    

    In this case, the identifier myFunc is only in scope inside the function, whereas testFunction is available in whatever scope it is declared. BUT (and there’s always a but when it comes to Internet Explorer) in IE below version 9 the myFunc identifier wrongly leaks out to the containing scope. Named function expressions are useful when you need to refer to the calling function (since arguments.callee is deprecated).


    Also note that the same is true for variable declarations:

    console.log(x); //undefined (not TypeError)
    var x = 10;
    

    You can imagine that the JavaScript engine interprets the code like this:

    var x; //Declaration is hoisted to top of scope, value is `undefined`
    console.log(x);
    x = 10; //Assignment happens where you expect it to
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have worked with OpenCL on a couple of projects, but have always written
I have worked many projects with no problems. But in current project, I tested
I have seen something like the following a couple times... and I hate it.
Hi I have worked for a couple companies now. Both used MVC to create
For the last couple of years I have worked with Silverlight (from version 2
My co-worker and I have come across this warning message a couple times recently.
I have worked within a web development company where we had our local machines,
I have worked with SOAP in SAAJ and JAXM, and I want to extend
I have worked with pointers a lot, but still whenever I work with them,
I have worked with JSF, so pretty much delighted with JSF datatable . Is

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.