What happens when you assign a value to an undeclared variable in JavaScript?
In non-strict mode, assigning a value to an undeclared variable creates a global variable. For example, if you write x = 10; without previously declaring x with var, let, or const, JavaScript will create x as a property of the global object (window in browsers). However, this behavior is considered bad practice and can lead to unexpected bugs. In 'strict mode' (activated by adding 'use strict'; at the top of your code), assigning to an undeclared variable will throw a ReferenceError, preventing the accidental creation of global variables.