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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:01:13+00:00 2026-05-26T05:01:13+00:00

Just a quick one… what’s the correct way to format a javascript function? I

  • 0

Just a quick one…

what’s the correct way to format a javascript function?

I see it like this:

function doThis(){
}

and like this:

doThis = function(){
}

Or maybe it make no difference. Please let me know whats best or if they both have different rasons or purposes.

Cheers

C

  • 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-26T05:01:14+00:00Added an answer on May 26, 2026 at 5:01 am

    They are two different things, although they both create a function (and assign it to a variable).

    function name () {
    }
    

    Is a function-statement (or “function declaration”). It is only legal to appear as a top-level script element or directly as an element of a function: that is, it is not legal for a function-statement to appear inside an if, or while, etc. All function statements are “lifted” to the top of the function (or script), thus the following is valid:

    a()
    function a () { alert("a") }
    

    In the form:

    variable = function name () {} // or variable = function () {}
    

    The function keyword is in a function-expression context: it creates a new function-object and the resulting function-object (just a “normal value”) is assigned to variable. The following is not valid because function-expressions are not lifted.

    var b
    b() // oops, does not evaluate to a function-object yet!
    b = function b () { alert("b") }
    

    All that being said, the “correct way” is to use the function-statement (“function declaration”) form unless there is reason to do otherwise.

    Happy coding.


    See also:

    • What is the difference between a function expression vs declaration in JavaScript?
    • Function Declarations vs. Function Expressions
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a quick one, Is there anyway to shorthand this? It's basically determining the
Just a quick one: Will SELECT ... WHERE name LIKE '...' query be faster
Just a quick one. What am I doing wrong here? $(#content a:not(target=_blank)).live(click, function(){ alert(You
This is just a quick one but I cant find what i need to
Just a quick one: what are peoples thoughts on using Action delegates for public
Just a quick question. Say a call a method like so mysql_pconnect(server,tator_w,password) or die(Unable
Just a quick one - I wrote a php script recently that dynamically creates
Just a quick question. I have one XML and I was hoping to tranform
just a quick query about safe/unsafe states in Dijkstra's Banker's algorithm ... If one
just a quick question. Is there a SIMPLE way to dynamic set the cell

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.