The with
statement is considered problematic because it makes the code harder to understand and maintain. It adds variables from an object to the scope, which can lead to confusion and unexpected behavior, especially in larger programs.
It is recommended to avoid using with
in modern JavaScript.
Example:
with (Math) {
console.log(sqrt(16)); // Works, but avoid it
}
Tags: intermediate, JavaScript, Best Practices
URL: https://www.tiktok.com/@jsmentoring/photo/7469541897426586913