Seth's Software Logo

Seth's Software

JavaScript Quirks

Explore the weird, wonderful, and sometimes confusing behaviors of JavaScript

Truthy & Falsy Values

JavaScript has some surprising truthy and falsy values. Not everything is as it seems!

Expected Behavior:
All falsy values return false, but '0', 'false', [], {}, and functions are truthy!

Floating Point Arithmetic

JavaScript uses IEEE 754 floating point numbers, which can lead to precision errors.

Expected Behavior:
0.1 + 0.2 = 0.30000000000000004 (not 0.3!)

Type Coercion Madness

JavaScript's automatic type conversion can produce bizarre results.

Expected Behavior:
[] + [] = '' (empty string), [] + {} = '[object Object]'

NaN is Not a Number... or is it?

NaN has some very peculiar properties that defy logic.

Expected Behavior:
NaN is type 'number' but NaN !== NaN! Use Number.isNaN() to check.

Array Constructor Quirks

The Array constructor behaves differently based on the number of arguments.

Expected Behavior:
Array(3) creates [empty × 3], Array(1,2,3) creates [1, 2, 3]

Equality Operators

The difference between == (loose) and === (strict) equality can be surprising.

Expected Behavior:
Use === for strict equality. [] == ![] is true (wat!)

parseInt() Surprises

parseInt() has some unexpected behaviors with certain inputs.

Expected Behavior:
['1','2','3'].map(parseInt) = [1, NaN, NaN] due to radix parameter!

The Mysterious 'this'

The value of 'this' depends on how a function is called, not where it's defined.

Expected Behavior:
Arrow functions don't have their own 'this', they inherit from parent scope

Automatic Semicolon Insertion (ASI)

JavaScript automatically inserts semicolons, sometimes in unexpected places.

Expected Behavior:
Return statements automatically get semicolons if followed by newline!

Want to learn more?

These quirks are features, not bugs! Understanding them makes you a better JavaScript developer.

Back to Home