Why can I not use var?


#1


https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/1/1?curriculum_id=506324b3a7dffd00020bf661


Hey

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.

Cheers


bool = true;

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


#2

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.


#3

Thanks for the explanation :]


#4

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