Q:

Function call javascript

I called helloworld and defined it with below two different ways:
1) With variable 
2) With function name itseld
var helloWorld = function() {
    return '2';
}

function helloWorld() {
    return '1';
}

alert (helloWorld());  // This alert 2, but in absence of "var helloWorld = ....", it alert "1". 

Can anyone please explain reason why it's calling var helloWord = ?  and not function helloWorld () ? 
Thank You !! 

A:

why it's calling var helloWord = ?  and not function helloWorld () ? 
Because functions definitions will be hoisted to the top.  And the assignments remains in the same place.  So it is getting overridden. 
This is how the interpreter sees the code,
function helloWorld() {
    return '1';
}

var helloWorld;

//the above function is getting overridden here. 
helloWorld = function() {
    return '2';
}

alert (helloWorld());

