Why can I not use var?




The below code works but I was wondering why I could create the variable bool without using the keyword var or did I not actually create a variable and just defined bool.


bool = true;

    console.log("Less is more!");
    bool = false;


No bool is still a valid variable in most cases the var keyword is optional but it is best practice to include it when defining variables.


Thanks for the explanation :]


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