Hoisting and Execution Context
What happens to variables declared without var, let, or const?
Variables assigned without using var, let, or const are implicitly declared as global variables (if not in strict mode). When you assign a value to a variable that hasn't been formally declared, JavaScript automatically creates that variable in the global scope, regardless of where the assignment happens. For example: ```javascript function test() { x = 10; // x is not declared with var, let, or const console.log(x); // 10 } test(); console.log(x); // 10 - x is available globally ``` This behavior can lead to unexpected bugs and is generally considered a bad practice, as it can accidentally overwrite existing global variables and makes code harder to maintain. That's why 'strict mode' was introduced - when you enable strict mode by adding `'use strict';` at the top of your script or function, assigning to undeclared variables will throw a ReferenceError instead: ```javascript 'use strict'; function test() { x = 10; // ReferenceError: x is not defined } ``` It's always recommended to explicitly declare variables using var, let, or const to clearly indicate their intended scope and avoid potential issues.