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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:12:28+00:00 2026-05-29T06:12:28+00:00

Possible Duplicate: What is the difference between a function expression vs declaration in JavaScript?

  • 0

Possible Duplicate:
What is the difference between a function expression vs declaration in JavaScript?
This JavaScript syntax I haven’t seen till now, what does it do really?

What is the difference between the following two ways of writing a function? I’ve seen both used, but I’m not sure which one is ‘correct’.

function init() {

}


init: function() {

},

And what are the advantages to writing it the second way?

  • 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-29T06:12:28+00:00Added an answer on May 29, 2026 at 6:12 am

    Function declaration

    function init() {
    
    }
    

    Function expression

    var init = function() {
    
    };
    

    The primary differences have to do with Variable Hoisting in JavaScript. You can read more here: http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting and http://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/

    By your example, I believe you are also interested in defining anonymous functions in object literals. Here is an example:

    //obj is the object name
    var obj = {
        //init is the property name or key and the anonymous function is the value
        init: function() {
        },
        anotherProp: 'some value'
    };
    

    This would be used like so:

    obj.init();
    alert(obj.anotherPorp);
    

    In object literals different properties of the object are defined with a key: value syntax and use commas to separate them.

    I would recommend going through this free series on JavaScript http://learn.appendto.com/lessons, it will answer a lot of these questions for you and give you a solid base to becoming a JS developer.

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

Sidebar

Related Questions

Possible Duplicate: What is the difference between a function expression vs declaration in Javascript?
Possible Duplicates: What is the difference between a function expression vs declaration in JavaScript?
Possible Duplicate: Difference between try-catch syntax for function What is the difference in the
Possible Duplicate: C++: What's the difference between function(myVar) and (function)myVar ? I have seen
Possible Duplicate: Difference between (function(){})(); and function(){}(); I have seen it a lot by
Possible Duplicate: When is a function try block useful? Difference between try-catch syntax for
Possible Duplicate: Is there a difference between (function() {…}()); and (function() {…})();? I've seen
Possible Duplicate: c difference between malloc and calloc Please explain the significance of this
Possible Duplicate: JavaScript: Class.method vs. Class.prototype.method What's the difference between creating a prototype like
Possible Duplicate: Difference between a Structure and a Union in C I see this

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.