[Insights](/insights/) / [Core Engineering Intelligence](/insights/core_engineering_intelligence/)

# JavaScript Pitfalls Guide

A practical guide to the most surprising JavaScript pitfalls every beginner faces — from type coercion and floating-point precision to equality quirks — explained through clear examples so you truly understand how JS works.

![Ivan Borshchov](https://static.devforth.io/adminusers/avatars/2026/48db9847-d461-40cd-b344-f2bd7b0d98ca-avatar_ivan@devforth.io_f4ce9df9-8363-4314-9345-28753c76a386.jpeg)

Ivan Borshchov

CEO & System Architect @ Devforth

Feb 12, 2026

![JavaScript Pitfalls Guide](https://static.devforth.io/posts/logo-svg/2026/d4941cc8-29b1-4094-b7a6-19263cd2e80d-logo-preview-1e30447b-097c-4738-b113-6b02a4f19c8c.svg)

![JavaScript Pitfalls Guide](https://static.devforth.io/posts/logo-svg/2026/d4941cc8-29b1-4094-b7a6-19263cd2e80d-logo-preview-1e30447b-097c-4738-b113-6b02a4f19c8c.svg)

This is a meme-inspired tour of "Thanks for inventing JavaScript" moments.

Crucial for every who writes at least one line of JS.

![Thanks for inventing JavaScript Meme](https://static.devforth.io/posts/images/2026/97291fa5-7c73-4423-877e-d23ab57fcaa6-image.png)

Thanks for inventing JavaScript Meme

This guide focuses on **examples first**.  
Each snippet shows the result in a comment.

## 1\. `NaN` is a `number`

```javascript
typeof NaN
// "number"
```

**Why?**  
In JS, `NaN` (Not-a-Number) is part of the numeric type system.

```javascript
Number.isNaN(NaN)
// true
```

## 2\. Floating Point Precision

```javascript
0.1 + 0.2 === 0.3
// false
```

```javascript
0.5 + 0.1 === 0.6
// true
```

```javascript
0.1 + 0.2
// 0.30000000000000004
```

```javascript
Math.abs((0.1 + 0.2) - 0.3) < Number.EPSILON
// true
```

## 3\. Large Integers Lose Precision

```javascript
9999999999999999
// 10000000000000000
```

```javascript
Number.MAX_SAFE_INTEGER
// 9007199254740991
```

```javascript
9999999999999999n
// 9999999999999999n
```

## 4\. `Math.max()` and `Math.min()` Without Arguments

```javascript
Math.max()
// -Infinity

Math.min()
// Infinity
```

## 5\. Truthy / Falsy Madness

```javascript
[] == 0
// true

"" == 0
// true

null == undefined
// true

null === undefined
// false
```

## 6\. `true == 1`

```javascript
true == 1
// true

true === 1
// false
```

## 7\. Boolean Arithmetic

```javascript
true + true + true === 3
// true

true - true
// 0
```

## 8\. String + Number

```javascript
9 + "1"
// "91"

91 - "1"
// 90
```

## 9\. Arrays + Arrays

```javascript
[] + []
// ""

[] + {}
// "[object Object]"
```

## 10\. `typeof null`

```javascript
typeof null
// "object"
```

## 11\. `NaN` Is Not Equal to Itself

```javascript
NaN === NaN
// false

Number.isNaN(NaN)
// true
```

## 12\. Implicit Conversion Tricks

```javascript
(![] + [])[+[]] + (![] + [])[+!+[]]
// "fa"
```

## 13\. Falsy Values

```javascript
false
0
-0
0n
""
null
undefined
NaN
```

## 14\. `parseInt` Gotcha

```javascript
parseInt("08")
// 8

parseInt("10", 10)
// 10
```

## 15\. `Array(3)` vs `[3]`

```javascript
Array(3)
// [ <3 empty items> ]

Array(3).fill(0).map(x => 1)
// [1,1,1]
```

## 16\. Comparing Objects

```javascript
{} === {}
// false

[] === []
// false
```

## 17\. Arrow vs Regular `this`

```javascript
const obj = {
  value: 42,
  regular() { return this.value },
  arrow: () => this.value
}

obj.regular()
// 42

obj.arrow()
// undefined
```

## 18\. `setTimeout` Loop Gotcha

```javascript
for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 0)
}
// 3
// 3
// 3
```

```javascript
for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 0)
}
// 0
// 1
// 2
```

# Survival Rules

1.  Prefer `===` over `==`
2.  Use `Number.isNaN`
3.  Avoid implicit coercion
4.  Use `BigInt` for large integers
5.  Use `let` / `const`
6.  Always specify radix in `parseInt`

JavaScript is not broken.  
It is just **very consistent in its own rules**.

[

Back to insights

](/insights)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Fjavascript-pitfalls-guide)[](https://bsky.app/intent/compose?text=JavaScript%20Pitfalls%20Guide%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fjavascript-pitfalls-guide)[](https://x.com/intent/tweet?text=JavaScript%20Pitfalls%20Guide%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fjavascript-pitfalls-guide)

[

Summarize with AI

](/lab/chat/?prompt=Extract%20main%20points%20from%20post%3A%20https%3A%2F%2Fdevforth.io%2Finsights%2Fjavascript-pitfalls-guide)

Table of Contents

-   [1\. NaN is a number](#_1-nan-is-a-number)
-   [2\. Floating Point Precision](#_2-floating-point-precision)
-   [3\. Large Integers Lose Precision](#_3-large-integers-lose-precision)
-   [4\. Math.max() and Math.min() Without Arguments](#_4-mathmax-and-mathmin-without-arguments)
-   [5\. Truthy / Falsy Madness](#_5-truthy-falsy-madness)
-   [6\. true == 1](#_6-true-1)
-   [7\. Boolean Arithmetic](#_7-boolean-arithmetic)
-   [8\. String + Number](#_8-string-number)
-   [9\. Arrays + Arrays](#_9-arrays-arrays)
-   [10\. typeof null](#_10-typeof-null)
-   [11\. NaN Is Not Equal to Itself](#_11-nan-is-not-equal-to-itself)
-   [12\. Implicit Conversion Tricks](#_12-implicit-conversion-tricks)
-   [13\. Falsy Values](#_13-falsy-values)
-   [14\. parseInt Gotcha](#_14-parseint-gotcha)
-   [15\. Array(3) vs \[3\]](#_15-array3-vs-3)
-   [16\. Comparing Objects](#_16-comparing-objects)
-   [17\. Arrow vs Regular this](#_17-arrow-vs-regular-this)
-   [18\. setTimeout Loop Gotcha](#_18-settimeout-loop-gotcha)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Fjavascript-pitfalls-guide)[](https://bsky.app/intent/compose?text=JavaScript%20Pitfalls%20Guide%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fjavascript-pitfalls-guide)[](https://x.com/intent/tweet?text=JavaScript%20Pitfalls%20Guide%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fjavascript-pitfalls-guide)
