Common AI coding mistakes and how to spot them
AI confidently uses functions that don't exist, especially for newer libraries or less common APIs.
const result = await fetch.json(url); // β Not a thing
array.unique(); // β Doesn't exist in JS
string.contains('text'); // β It's .includes()
AI training data includes old code. It might suggest deprecated patterns or old API versions.
componentWillMount() { } // β Deprecated in React
new Buffer('data') // β Deprecated, use Buffer.from()
request.get(url) // β request package is deprecated
Classic programming mistake that AI makes frequently, especially in loops and array operations.
for (let i = 0; i <= arr.length; i++) // β Should be <
arr.slice(0, arr.length - 1) // Sometimes wrong depending on intent
AI often forgets await, uses it incorrectly, or creates race conditions.
// Forgot await
const data = fetchData(); // β Returns Promise, not data
// Sequential when could be parallel
const a = await getA();
const b = await getB(); // β Could use Promise.all
// forEach doesn't wait
arr.forEach(async (item) => { // β Doesn't wait for completion
await process(item);
});
AI sometimes ignores JavaScript's quirky type coercion rules.
if (value == null) // Might not catch undefined how you expect
if (arr.length) // Truthy check, but 0 is falsy
const num = parseInt(input) // Missing radix, or NaN not handled
AI frequently generates code vulnerable to SQL injection, XSS, and command injection.
// SQL injection
db.query(`SELECT * FROM users WHERE id = ${userId}`) // β
// XSS
element.innerHTML = userInput // β
// Command injection
exec(`rm ${filename}`) // β
AI often uses insecure-but-simple options for demos that shouldn't go to production.
cors({ origin: '*' }) // β Too permissive
jwt.sign(data, 'secret') // β Weak secret
http.createServer() // β Should be https
AI doesn't say "I'm not sure" or "this might not work." It presents everything with equal confidence. The more obscure or complex the task, the more likely it's wrongβbut it won't tell you that.