A JavaScript object is a mapping between keys and values. Keys are
strings and values can be anything. This makes objects a natural fit
for hashmaps.
Functions are regular objects with the additional capability of being
callable.
FROM https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#.22Normal.22_objects.2C_and_functions
This mean that you can do things like:
function test(){
console.log(1);
}
var a = test;
a();
or
var test2 = function(){
console.log(2);
}
or autocall
//sorry for the indentation.
(
function(){
console.log(3);
}
)()
Or create structures
var testHash = {
a : 1,
b : function(){
console.log(4);
}
}
testHash.b();
testHash['b']();
And create function difficult to call:
//in a browser environment
window['test3'] = function(){
console.log(5);
}
window['test space'] = function(){
console.log(6);
}
test3() //no error
test space() //error :D
EDIT: The user wants to know more about autocall functions:
Why this work?
(
function(){
console.log(3);
}
)()
It easy to follow in 2 steps:
The parenthesis, if we know that a function is like other variables, and we know that the parenthesis is only for made groups or call functions.
var test_1 = 'string example';
var length = (test_1).length; // the same that test_1.length
Make sense in:
var test_1 = 'string';
var test_2 = ' example';
var length = (test_1 + test_2).length; // the same that test_1.length
instead of:
var test_1 = 'string';
var test_2 = ' example';
var aux = test_1 + test_2;
var length = aux.length; // the same that test_1.length
Now, Do this make sense for you?:
var length = ('string example').length; // instead the first example
Second step, we can change the string for the function.. and call it
( function(){ ... } )()
why is this interesting?
Well, now appear the concept of closure.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
The closures are a very important tool in javascript.