Thursday, March 8, 2012

Notes from Javascript in 10 mins

  • You won’t run into any trouble if you always end lines with semicolons.
  • Every function returns a value.If you don’t use a return statement, then your function returns undefined
  • Be careful how you define a variable. Always use var keyword
  • Lazy scoping and mutability. The simplest way to fix this is to wrap our assignment in an anonymous
    function that is evaluated immediately, introducing another layer of scope.
  • Never use the == operator unless you really want this behavior, x == null might be an exception
  • Boxed values are always truthy and can store properties. Unboxed values will
    silently fail to store properties 
  • All HTML objects, whether or not they’re somehow native, will be boxed.
  • Throwing things - throw new Error(3)
  • Implied global variables should never be used
  • In JavaScript blocks do not have scope. Only functions have scope. Do not use blocks except as required by the compound statements.  
  • The eval function is the most misused feature of JavaScript. Avoid it.
  • The eval function has aliases. Do not use the Function constructor. Do not pass strings to setTimeout or setInterval.

1 comment:

  1. Suggest to read http://javascript.crockford.com/code.html

    ReplyDelete