Functions are one of the basic building blocks in JavaScript. To use a function, you must define it somewhere in the scope from which you wish to call it.

Named function

A function defined with a name is called named function. It can be called using this name.

function functionName() {

// the above function is called as follows
functionName() // prints 'called'

Anonymous Function

A function defined without name. It can be used if its initialised on a variable.

Following is an example

var a = function () {

      // as the function defination is assigned
      // to variable 'a', it can be called as follows
      a() // prints 'called'