Skip to content
- Use JSLint to determine if what you are doing is sensible.
- Avoid “/* … */” for comments, “*/” appears in useful constructs in javascript. Use “//”.
- Javascript strings are 16-bit unicode. It has no character type, only string.
- All numbers are numeric, there is no int/float/etc.
- The value
Infinity represents all values greater than ~1.79E+308
- Javascript has functional scoping. Braces do not denote scope. Thus, declare variables at the top of functions not within braces.
- Falsy values:
false, null, undefined, ” (empty string), 0, NaN. Everything else is truthy.
- If using a
for ... in loop you must you hasOwnProperty.
typeof returns "object" for an array and for null.
- Declare
var that = this; in a function so that inner functions can access that function’s this value. (Prefer “self”?)
- Because functions are first class objects, javascript supports currying.
- General memoizer (p. 45)
- Don’t use
new at all.
- Functional inheritance (p. 52).
- Do not use “/g” with
RegExp.test.
- Prefer “
if (” to “if(” because “if(” looks like a method invocation.
- K&R-style curly braces because of how
return works in javascript.
- Always pass the second parameter (radix) to
parseInt.
- Always use
=== and !== not == and !=.
- Do not use
with.
- Use
JSON.parse not eval.
- Do not use
++ and --.