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

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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 would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I want to construct a data frame in an Rcpp function, but when I

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.