cd /news/developer-tools/do-not-pass-parseint-directly-to-a-q… · home › topics › developer-tools › article
[ARTICLE · art-177903] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Do Not Pass parseInt Directly to a Quantity Array’s map Callback

A developer demonstrated that passing parseInt directly to Array.prototype.map produces inconsistent results on identical strings, because map forwards the array index as parseInt's radix argument. In a Node.js test, mapping parseInt over ['10','10','10'] yielded 10, NaN and 2, while an explicit arrow function supplying radix 10 returned [10,10,10]. The writeup, prepared for YX Fulfillment, notes the fix does not validate full field contents, since parseInt('10units', 10) still returns 10.

key takeaway

Wrap parseInt in an arrow function that passes radix 10 explicitly, since map forwards the array index as the radix and turns ['10','10','10'] into [10, NaN, 2].

by read2 min views3 publishedNov 28, 2026

Passing parseInt directly to map can make identical strings produce different results. The array index becomes parseInt's radix argument, so the callback's position changes the interpretation. Wrap the call and supply the intended radix explicitly.

Prepared with AI assistance for YX Fulfillment, this is a small JavaScript learning example. It does not process a customer order file or prove that arbitrary quantity text is safe to import.

MDN's map documentation explains that map supplies the element, index and array to its callback. parseInt accepts a radix as its second parameter. A function that seems convenient for one direct call can therefore have a different contract when passed as a callback.

const assert = require('node:assert/strict');
const fields = ['10', '10', '10'];
const accidental = fields.map(parseInt);
assert.equal(accidental[0], 10);
assert.ok(Number.isNaN(accidental[1]));
assert.equal(accidental[2], 2);
const explicit = fields.map(value => parseInt(value, 10));
assert.deepEqual(explicit, [10, 10, 10]);
assert.deepEqual(fields, ['10', '10', '10']);
assert.deepEqual([].map(value => parseInt(value, 10)), []);
assert.equal(parseInt('10units', 10), 10);
assert.ok(Number.isNaN(parseInt('units', 10)));
console.log('Callback radix hazard and explicit callback verified');

For the three identical strings, the accidental callback receives radices 0, 1 and 2. The first result is decimal ten, the second is NaN and the third is binary ten, which has numeric value two. An explicit arrow function accepts the value and deliberately passes radix 10 instead of forwarding the index.

This matters in a Shopify fulfillment import because changing the row position should not silently change the interpretation of the same quantity text. A Shopify 3PL integration and a supplier-led drop shipping feed may use different schemas; each still needs an explicit conversion contract before work is created.

The final assertion demonstrates a limit: parseInt still accepts the numeric prefix of '10units'. The callback repair prevents an unintended radix; it does not validate an entire field. An actual China fulfillment import must define permitted syntax, range and missing-value handling separately.

When a China 3PL project is discussed under a search label such as “International Fulfillment for Folligen”, that label is context for requirements, not a claim about a client relationship. Use synthetic fixtures to agree the input contract before touching live data.

I executed the final code in Node.js, checking all three accidental results, the explicit decimal callback, the unchanged source array and an empty array. The photo shows a warehouse workstation and does not depict the software test.

Workers, cartons and packing materials at a warehouse workstation.

── more in #developer-tools 4 stories · sorted by recency
── more on @yx fulfillment 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/do-not-pass-parseint…] indexed:0 read:2min 2026-11-28 · —