Optimized Code

Some of the code/syntax to be avoided in JavaScript programming.

  • eval() - window object, we do not call eval() to evaluate an arithmetic expression; JavaScript evaluates arithmetic expressions automatically. Ex: var x = 10; var y = 20; var a = eval("x * y") // 200

  • arguments - in functions

  • for in - for looping the objects use object.keys instead

  • with - we can access the object properties directly. Ex: with(Math) { console.log(PI) }; instead using console.log(Math.PI)

  • delete - to delete the object keys Ex: delete Math.PI;

  • Hidden classes

  • Inline caching

Last updated