for...in lặp qua enumerable property names của object (cả own lẫn inherited từ prototype chain). for...of lặp qua values của iterable objects (Array, String, Map, Set, Generator). for...of thường dùng cho arrays, for...in cho objects.
Tránh for...in với arrays vì có thể lặp qua inherited properties từ prototype. Dùng Object.hasOwn(obj, key) trong vòng lặp for...in để chỉ xử lý own properties khi cần.
for...in iterates over enumerable property names — both own AND inherited from the prototype chain. for...of iterates over the values of iterable objects (Array, String, Map, Set, Generator). for...of is typically used with arrays, for...in with objects.
Avoid for...in with arrays since it may iterate over prototype-inherited properties. Use Object.hasOwn(obj, key) inside the loop to process only own properties when needed.