The JS course uses the old method of declaring functions

I noticed that the Js course uses the old method of declaring functions.
I consider the new way easier and better than the old one. It is also more efficient.
var myFunction = function(param) {
  //code code code; };
New (W3 standard):
function myFunction(param) {
  //code code code; }

1 Like

You’re right, and the Python course and HTML & CSS courses (and probably more) are also outdated, but unfortunately updating these courses will take a while and are not Codecademy’s top priority right now.

Hey Fire-Man,

Both forms are valid (AFAIK) - although I’m not sure where in the spec I would check that (and I don’t feel like spending a whole lot if time looking through there right now), so you may be right - they just work differently:

The difference is that functionOne is defined at run-time, whereas functionTwo is defined at parse-time for a script block.
- var functionName = function() {} vs function functionName() {}

Well, it’s usually a good idea to post a source of your information and… simple arguments.

  • Function expression is an older way? Source?
  • Easier and better. In what matter?
  • More efficient. Post description of test methods and results.
  • Function definition is a W3C standard. May I see a source of this information?

I don’t want to be mean, but as a programmer you have to be able to state and defend your opinions. Base your arguments on facts and sources.

I can tell you why I don’t use function definitions.


Syntax of function expression is more readable and clear:

var myFunction = function(x, y) { ... }

You can immediately tell that we have created an variable with a function value.


The whole body of function definition is hoisted. In the result we have a code that is sometimes unpredictable and hard to debug (because you are not able to easily track logic flow by reading code with function definitions). You can say that function definitions are more forgiving, but declaration of function after function call (in the code of course) is not a valuable feature in my opinion. What do you think?


With use of simple grouping I can make my function expression immediately invoke.


In the most companies I worked for we were writing code compliant with the Crockford style guide, where function expressions are recommended (mostly because of my 1 point). Source -> JavaScript: The Good Parts.