Solo Flight - Why there should be brackets before while?


#1


var bool = true
var soloLoop = function()
{ //I don't understand why there's bracket before while loop
    while(bool) 
    {
        console.log("Looped once!");
        bool = false;
    }
} //I don't understand why there's bracket before while loop

soloLoop();


#2

Because that is the enclosure of the function body.

var foo = function () {
   // code is inside function body
};

When there is code inside, {} denotes a code block.

Aside

When there are key-value pairs (properties) inside, {} denotes a plain object.

var person = {
    name: "Wee Gillis",
    age: 19
};

#3

Thanks for your explanation!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.