1. NaN 是什麼?
NaN = Not a Number(不是數字)。
代表「預期是數字,卻得不到合法數字」的結果。
型別依然是 number。
12console.log(typeof NaN); // "number"
2. 什麼時候會出現 NaN?
無法正確轉換成數字 時:
123Number("hello"); // NaNparseInt("hello"); // NaN
數學運算錯誤 時:
1230 / 0; // NaNMath.sqrt(-1); // NaN
非法運算 時:
123let x = "apple" * 10;console.log(x); // NaN
3. NaN 的特性
NaN 不等於任何東西,包括自己
12console.log(NaN === NaN); // false
檢查 NaN 的方法
123Number.isNaN(NaN); // true ✅ (推薦)isNaN("hel ...








