# Things to avoid in JavaScript (the bad parts)

> A list of things to avoid when writing JavaScript, like using new Object() over literals, == instead of ===, eval, with, and editing built-in prototypes.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2012-07-16 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/things-to-avoid-in-javascript-bad-parts/

- Avoid creating a new object by using `new Object()`. Use the object literal syntax `{}` instead.
- Same thing for arrays, favor `[]` over `new Array()`.
- Avoid blocks except where statements require them (`if`, `switch`, loops, `try`).
- Never assign inside an `if` of `while` statements condition part
- Never use `==` and `!=`. Use `===` and `!==` instead.
- Never use `eval`. Why? It has performance issues (it runs the interpreter/compiler), it has security issues (code injection if used with user input), difficulties in debugging.
- Never use `with`, as it modifies the scope chain and can be a source of confusion.
- Always pass functions to [`setTimeout` and `setInterval`](https://flaviocopes.com/javascript-timers/)
- Never use `Array` as an associative arrays, use `Object` instead. The part of the `Array` object that provides that functionality is in fact provided by the `Object` prototype, so you could really have used a `Date` object for that same thing.
- Don't use `\` at the end of a string to create a multiline string, it's not part of ECMAScript. Use string concatenation `' string1 ' + ' string2 '` instead
- Never modify the prototypes of the built-in objects `Object` and `Array`. Modify other prototypes of other objects such as `Function` with caution as it could lead to bugs hard to debug.
