// =============================== // JavaScript Hall of Shame 🤡 από το ChatGPT // =============================== // 1. String + Number = string (γιατί έτσι) "5" + 1; // "51" -> string concatenation "5" - 1; // 4 -> numeric coercion // 2. Floating point madness (IEEE-754) 0.1 + 0.2; // 0.30000000000000004 // 3. NaN: Not a Number (αλλά typeof number) NaN === NaN; // false -> NaN δεν ισούται με τον εαυτό του typeof NaN; // "number" // 4. Άδειες δομές που κάνουν μαγεία [] + []; // "" -> empty string [] + {}; // "[object Object]" {} + []; // 0 -> parsing + coercion (global scope) // 5. Loose equality (ΜΗΝ ΤΟ ΧΡΗΣΙΜΟΠΟΙΕΙΣ) false == 0; // true false == ""; // true 0 == ""; // true false === 0; // false -> strict equality (σωστό) // 6. null vs undefined null == undefined; // true null === undefined;// false typeof null; // "object" <- legacy bug 🤡 // 7. Arrays και truthiness typeof []; // "object" [] == false; // true [] == ![]; // true <- WTF moment // 8. Reference equality {} === {}; // false [] === []; // false // 9. this: το απόλυτο χάος const obj = { x: 42, getX() { return this.x; } }; obj.getX(); // 42 const f = obj.getX; f(); // undefined (ή error σε strict mode) // 10. Arrow functions αλλάζουν το this const obj2 = { x: 42, getX: () => this.x }; obj2.getX(); // undefined -> arrow δεν έχει own this // 11. Automatic Semicolon Insertion ☠️ function returnsObject() { return { ok: true }; } returnsObject(); // undefined (όχι object) // 12. parseInt παγίδα parseInt("08"); // 8 (παλιά: 0 λόγω octal) parseInt("10", 2); // 2 (binary parsing) // 13. Default values gone wrong function withDefault(x) { x = x || 10; return x; } withDefault(0); // 10 🤯 withDefault(null); // 10 withDefault(undefined);// 10 // 14. typeof classes typeof class A {}; // "function" // 15. Functions είναι objects typeof function() {}; // "function" // 16. + operator κάνει ό,τι θέλει true + true; // 2 true + false; // 1 false + false; // 0 // 17. Boolean coercion madness !!"false"; // true !!0; // false !![]; // true // 18. Equality chain disaster 0 == "0"; // true 0 == []; // true "0" == []; // false // 19. delete συμπεριφέρεται αλλοπρόσαλλα const arr = [1, 2, 3]; delete arr[1]; arr; // [1, , 3] arr.length; // 3 // 20. Math που δεν είναι math Math.max(); // -Infinity Math.min(); // Infinity // 21. Object keys πάντα strings const o = {}; o[1] = "one"; o["1"]; // "one" // 22. for...in σε arrays (μην το κάνεις) for (let i in [10, 20, 30]) { i; // "0", "1", "2" (strings!) } // 23. Implicit globals (χωρίς strict) function leak() { x = 10; } leak(); x; // 10 (global pollution) // 24. JSON δεν υποστηρίζει undefined JSON.stringify({ a: undefined }); // "{}" // 25. BONUS – Το απόλυτο WTF [] == []; // false [] == ![]; // true