dimanche 6 décembre 2015

Javascript function evaluation as variable

I wasn't really sure what to name this question, as that is almost the question itself. Basically I was messing with some code and found something that I can't quite explain. Here's a simplification:

function foo (a, b) {
    if (foo) {
        console.log("foo is true");
    } else if (!foo) {
        console.log("foo is false");
    } 
}

foo();

This outputs "foo is true", but what I don't understand is how is Js evaluating a function without executing it ( lack of (); ) and how can I execute it even without passing parameters defined in the function. Maybe I should say that the only language I really know is java.

Aucun commentaire:

Enregistrer un commentaire