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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:17:11+00:00 2026-05-13T06:17:11+00:00

What’s the difference between these two ways of declaring a function? function someFunc() {

  • 0

What’s the difference between these two ways of declaring a function?

function someFunc() { ... }

var someFunc = function() { ... }

I’m not asking in the technical sense. I’m not asking which is better for readability, or which style is preferred.

  • 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-13T06:17:11+00:00Added an answer on May 13, 2026 at 6:17 am

    I am on different opinion with most of the people here. Technically this syntax may mean the same for declaring functions both ways
    (I stand incorrect on my last statement. I read up on a diff post why they are technically diff and I’ll add in the end, why)
    ; but the way they play a role in evolving patterns is massive. I would highly recommend “Javascript: The Good Parts” by Doughlas Crockford.

    But to prove my point in a subtle and a simple manner; here is a small example.

    //Global function existing to serve everyone
    function swearOutLoud(swearWord) {
        alert("You "+ swearWord);           
    }
    //global functions' territory ends here
    
    //here is mr. spongebob. He is very passionate about his objects; but he's a bit rude.
    var spongeBob = {
        name : "squarePants",
        swear : function(swearWord) {
                    name = "spongy";
                    alert("You "+ swearWord);
                    return this;
                }
    }
    
    //finally spongebob learns good manners too. EVOLUTION!
    spongeBob.apologize = function() {
        alert("Hey " + this.name + ", I'm sorry man!");
        return this;
    }
    
    
    //Ask spongebob to swear and then apologize in one go (CASCADING EFFECT!!)
    alert(spongeBob.swear("twit").apologize());
    

    if you look at the code above I declared a function with a name swearOutLoud. Which would take a swear word from any object or a call and will give you the output. It can do operations on any object using the “this” parameter that is passed to it and the arguments.

    However second declaration is declared as an attribute of object called “spongeBob”. This is important to note; as here I am moving towards an object driven behavior. While I am also maintaining “cascading effect” as I return “this” if i have nothing else to return.

    Somthing similar is done in jquery; and this cascading pattern is important if you are trying to write a framework or something. You’ll link it to Builder design pattern also.

    But with functions declared as an attributes of an object I am able to achieve an object centric behavior which leads to a better programming paradigm. Unless designed well; individual functions declared outside with global access lead to a non-object oriented way of coding. I somehow prefer the latter.

    To see cascading in effect, look at the last statement where you can ask spongebob to swear and apologize at once; even though apologize was added as an attribute later on.

    I hope I make my point clear. The difference from a technical perspective may be small; but from design and code evolution perspective it’s huge and makes a world of a difference.

    But thats just me! Take it or leave it. 🙂

    EDIT:

    So both the calls are technically different; because a named declaration is tied to global namespace and is defined at parse time. So can be called even before the function is declared.

     //success
     swearOutLoud("Damn");
    
    function swearOutLoud(swearWord) {
        alert("You " + swearWord)
    }
    

    Above code will work properly. But code below will not.

    swear("Damn!");
        var swear = function(swearWord) {
        console.log(swearWord);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 488k
  • Answers 488k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer yes, it is, but you will have to make a… May 16, 2026 at 8:48 am
  • Editorial Team
    Editorial Team added an answer That's because UIElementCollection (the type of the Children property) doesn't… May 16, 2026 at 8:48 am
  • Editorial Team
    Editorial Team added an answer Dim matchingUsers As List(Of XmlUser) = Me.Store.Users.FindAll( _ Function(user As… May 16, 2026 at 8:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.