Stack.get(NaN) returns the first item instead of the fallback

Author: xu91102Created Sep 26, 2026Updated Sep 26, 2026

Stack.get(NaN) returns the first item instead of the supplied fallback or undefined:

javascript
const stack = Stack.of('first', 'second');
stack.get(NaN); // 'first', expected undefined
stack.get(Number('invalid'), 'missing'); // 'first', expected 'missing'

The traversal condition treats NaN as falsy and returns the untouched head. This can turn a failed numeric conversion into a seemingly successful lookup. Reproduced on current main with Node 22.23.2, macOS. The regression test fails on main. Prepared with Codex assistance.

Source: immutable-js/immutable-js