🔄 for…of vs for…in in JavaScript – quick reminder for (let value of array) → gives you the values directly → clean, readable, what you want 95% of the time for (let key in object) → gives you the property names / indices (as strings!) → iterates over enumerable properties (including prototype chain ⚠️) Quick rule of thumb: ✅ Want values? → for…of ✅ Need keys on a plain object? → for…in (with hasOwn guard) 🚫 for…in on arrays? Usually better to avoid. Modern alternatives I reach for most often: • array.entries() + for…of • Object.entries() + for…of / .forEach #JavaScript #WebDevelopment #CodingTips #Frontend #TypeScript
Pro developer 👌
Clear and practical reminder 👏 for…of + Object.entries() is my go-to combo as well.