Skip to content

Instantly share code, notes, and snippets.

@richardcornish
Last active August 10, 2023 21:39
Show Gist options
  • Save richardcornish/fcd541ba87946d4ff6dd to your computer and use it in GitHub Desktop.
Save richardcornish/fcd541ba87946d4ff6dd to your computer and use it in GitHub Desktop.
An incomplete list of bizarre failings of the JavaScript programming language
  • Prototypal inheritance forces an unstated empty object onto your object with key prototype
  • functions can act as object constructors but with the same syntax
  • empty array members break loops
  • Infinity/-Infinity
  • +0/-0
  • null is an object
  • testing NaN === NaN is always false
  • typeof always returns object" for all different reference types
  • the type of NaN (not a number) is literally "number" but as a string
  • void looks like a Java class but its only job is to return undefined
  • undefined is a global var which is different from but has type of undefined
  • undefined can also be redefined
  • null and undefined both exist
  • reference types were made to look like Java and should be avoided but are still force converted on to you under the hood on some objects
  • the DOM api in general
  • this
  • callback hell
  • hoisting
  • parseInt() defaults to base 2 not base 10
  • .sort converts array members to strings making 10 appear before 1
  • { } + { } = "" empty string
  • 0.1 + 0.2 = 0.30000000000000004
  • you can monkey patch/blow away almost any built-in method in the language
  • "0" and "false" are truthy values
  • + symbol (unary operator) overloaded for addition and concatenation
  • auto semicolon insertion
  • new required for object instantiation vs function reference with no error
  • new Boolean(false) is true
  • global vars infect you everywhere
  • oh and don't forget all browsers implement it a little bit differently just like CSS—especially critical features like event handlers, e.g. click
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment