Instantly share code, notes, and snippets.

View JavaScript Class

Throughout this article, I will use Java's Object-Oriented Programming terminologies such as static, private and public.

Pattern 1: Self-construction

This pattern exploits scoping to allow for private and public fields and methods. It is named as Self-construction because the class function (or constructor) has to assign instance methods one by one.

View JavaScript Closure

This describes the common mistake with using closures in JavaScript.

A function defines a new environment


function makeCounter()
  var obj = {counter: 0};
View JavaScript Implicit Boolean

Implicit Boolean Conversion in JavaScript

Only the following values are considered false:

  • null
  • undefined
  • '' (empty string)
  • 0
  • NaN
  • false