JavaScript Functions: Made Quick & EASY

Coming from a C++ background, I found JavaScript functions to be very strange, for several reasons:

  1. Functions can be assigned to variables.
  2. Functions can be stored inside arrays.
  3. Functions themselves really are true objects.
  4. You can even have anonymous functions, i.e. a function without a name.

Functions vs Subroutines

Ultimately, the difference is how any given language chooses to use these two terms, but essentially, they can be thought of as being the same thing. Some languages speak only of functions, some only of subroutines, and some of both… and so there really isn’t much point in trying to be too clever when it comes to arguing over their definitions.

For example, here’s a quote from IBM “Subroutines and functions are routines made up of a sequence of instructions that can receive data, process it, and return a value.”