Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Editting someone's edits
Source Link
Richard Garside
  • 89.5k
  • 12
  • 88
  • 98

var functionName = function() {} vs function functionName() {} in JavaScript

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.

The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.

The two ways are:

var functionOne = function() {
 // Some code
};

ORAnd,

function functionTwo() {
 // Some code
}

Question: What What are the reasonsreasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?

var functionName = function() {} vs function functionName() {} in JavaScript

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.

The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.

The two ways are:

var functionOne = function() {
 // Some code
};

OR

function functionTwo() {
 // Some code
}

Question: What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?

var functionName = function() {} vs function functionName() {}

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.

The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.

The two ways are:

var functionOne = function() {
 // Some code
};

And,

function functionTwo() {
 // Some code
}

What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?

added more clarity and method tag
Source Link
webwizard
  • 3.8k
  • 1
  • 25
  • 38

var functionName = function() {} vs function functionName() {} in JavaScript

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.

The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.

The two ways are:

var functionOne = function() {
 // Some code
};

OR

function functionTwo() {
 // Some code
}

WhatQuestion: What are the reasonsreasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?

var functionName = function() {} vs function functionName() {}

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.

The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.

The two ways are:

var functionOne = function() {
 // Some code
};
function functionTwo() {
 // Some code
}

What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?

var functionName = function() {} vs function functionName() {} in JavaScript

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.

The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.

The two ways are:

var functionOne = function() {
 // Some code
};

OR

function functionTwo() {
 // Some code
}

Question: What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?

Rollback to Revision 26
Source Link
Richard Garside
  • 89.5k
  • 12
  • 88
  • 98

What is the difference betweenI've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the methods belowcode and their advantages/disadvantages?make it more consistent.

The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.

The two ways are:

var functionOne = function() {
 // ...Some code
};
function functionTwo() {
 // ...Some code
}

What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?

What is the difference between the methods below and their advantages/disadvantages?

var functionOne = function() {
 // ...
};
function functionTwo() {
 // ...
}

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.

The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.

The two ways are:

var functionOne = function() {
 // Some code
};
function functionTwo() {
 // Some code
}

What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?

Shorten.
Source Link
Mateen Ulhaq
  • 27.9k
  • 21
  • 122
  • 155
Loading
Accepted one grammar edit from last update, but not the title change.
Source Link
Richard Garside
  • 89.5k
  • 12
  • 88
  • 98
Loading
Rollback to Revision 23 - Edit approval overridden by post owner or moderator
Source Link
Richard Garside
  • 89.5k
  • 12
  • 88
  • 98
Loading
Phrased title as a question, improved English and formatting
Source Link
Loading
Rollback to Revision 21
Source Link
Richard Garside
  • 89.5k
  • 12
  • 88
  • 98
Loading
Grammar.
Source Link
Luca Kiebel
  • 10.1k
  • 7
  • 34
  • 47
Loading
Rollback to Revision 17
Source Link
Richard Garside
  • 89.5k
  • 12
  • 88
  • 98
Loading
added 590 characters in body
Source Link
m87
  • 4.5k
  • 3
  • 19
  • 31
Loading
Copy edited (e.g. ref. <http://en.wikipedia.org/wiki/JavaScript>).
Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134
Loading
Attempted to make the title clearer
Link
Steve Chambers
  • 39.8k
  • 29
  • 179
  • 222
Loading
Notice removed Reward existing answer by Etheryte
Bounty Ended with T.J. Crowder's answer chosen by Etheryte
Notice added Reward existing answer by Etheryte
Bounty Started worth 200 reputation by Etheryte
Post Merged (destination) from stackoverflow.com/questions/22173394/…
edited title
Link
000
  • 27.3k
  • 10
  • 74
  • 103
Loading
Question Protected by NullPoiиteя
Rollback to Revision 14
Link
Richard Garside
  • 89.5k
  • 12
  • 88
  • 98
Loading
Removed tag from title.
Link
Ry-
  • 226.3k
  • 56
  • 496
  • 504
Loading
tags++
Link
hippietrail
  • 17.3k
  • 21
  • 114
  • 181
Loading
Added semicolon as suggested by xavierm02.
Source Link
Richard Garside
  • 89.5k
  • 12
  • 88
  • 98
Loading
edited tags
Link
ajax333221
  • 11.9k
  • 16
  • 65
  • 95
Loading
1
2
lang-js

AltStyle によって変換されたページ (->オリジナル) /