Skip to content

Latest commit

 

History

History
19 lines (12 loc) · 793 Bytes

why_do_you_need_to_avoid_with_statement.md

File metadata and controls

19 lines (12 loc) · 793 Bytes

Why do you need to avoid with statement?

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