drpanwe

Untitled

Dec 12th, 2025
4,523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ===============================
  2. // JavaScript Hall of Shame 🤡 από το ChatGPT
  3. // ===============================
  4.  
  5. // 1. String + Number = string (γιατί έτσι)
  6. "5" + 1;           // "51"   -> string concatenation
  7. "5" - 1;           // 4      -> numeric coercion
  8.  
  9. // 2. Floating point madness (IEEE-754)
  10. 0.1 + 0.2;         // 0.30000000000000004
  11.  
  12. // 3. NaN: Not a Number (αλλά typeof number)
  13. NaN === NaN;       // false  -> NaN δεν ισούται με τον εαυτό του
  14. typeof NaN;        // "number"
  15.  
  16. // 4. Άδειες δομές που κάνουν μαγεία
  17. [] + [];           // ""     -> empty string
  18. [] + {};           // "[object Object]"
  19. {} + [];           // 0      -> parsing + coercion (global scope)
  20.  
  21. // 5. Loose equality (ΜΗΝ ΤΟ ΧΡΗΣΙΜΟΠΟΙΕΙΣ)
  22. false == 0;        // true
  23. false == "";       // true
  24. 0 == "";           // true
  25.  
  26. false === 0;       // false -> strict equality (σωστό)
  27.  
  28. // 6. null vs undefined
  29. null == undefined; // true
  30. null === undefined;// false
  31. typeof null;       // "object"  <- legacy bug 🤡
  32.  
  33. // 7. Arrays και truthiness
  34. typeof [];         // "object"
  35. [] == false;       // true
  36. [] == ![];         // true   <- WTF moment
  37.  
  38. // 8. Reference equality
  39. {} === {};         // false
  40. [] === [];         // false
  41.  
  42. // 9. this: το απόλυτο χάος
  43. const obj = {
  44.   x: 42,
  45.   getX() {
  46.     return this.x;
  47.   }
  48. };
  49.  
  50. obj.getX();        // 42
  51. const f = obj.getX;
  52. f();               // undefined (ή error σε strict mode)
  53.  
  54. // 10. Arrow functions αλλάζουν το this
  55. const obj2 = {
  56.   x: 42,
  57.   getX: () => this.x
  58. };
  59.  
  60. obj2.getX();       // undefined -> arrow δεν έχει own this
  61.  
  62. // 11. Automatic Semicolon Insertion ☠️
  63. function returnsObject() {
  64.   return
  65.   {
  66.     ok: true
  67.   };
  68. }
  69.  
  70. returnsObject();   // undefined (όχι object)
  71.  
  72. // 12. parseInt παγίδα
  73. parseInt("08");        // 8  (παλιά: 0 λόγω octal)
  74. parseInt("10", 2);    // 2  (binary parsing)
  75.  
  76. // 13. Default values gone wrong
  77. function withDefault(x) {
  78.   x = x || 10;
  79.   return x;
  80. }
  81.  
  82. withDefault(0);       // 10 🤯
  83. withDefault(null);    // 10
  84. withDefault(undefined);// 10
  85.  
  86. // 14. typeof classes
  87. typeof class A {};    // "function"
  88.  
  89. // 15. Functions είναι objects
  90. typeof function() {}; // "function"
  91.  
  92. // 16. + operator κάνει ό,τι θέλει
  93. true + true;          // 2
  94. true + false;         // 1
  95. false + false;        // 0
  96.  
  97. // 17. Boolean coercion madness
  98. !!"false";            // true
  99. !!0;                  // false
  100. !![];                 // true
  101.  
  102. // 18. Equality chain disaster
  103. 0 == "0";             // true
  104. 0 == [];              // true
  105. "0" == [];            // false
  106.  
  107. // 19. delete συμπεριφέρεται αλλοπρόσαλλα
  108. const arr = [1, 2, 3];
  109. delete arr[1];
  110. arr;                  // [1, <empty>, 3]
  111. arr.length;           // 3
  112.  
  113. // 20. Math που δεν είναι math
  114. Math.max();           // -Infinity
  115. Math.min();           // Infinity
  116.  
  117. // 21. Object keys πάντα strings
  118. const o = {};
  119. o[1] = "one";
  120. o["1"];               // "one"
  121.  
  122. // 22. for...in σε arrays (μην το κάνεις)
  123. for (let i in [10, 20, 30]) {
  124.   i;                  // "0", "1", "2" (strings!)
  125. }
  126.  
  127. // 23. Implicit globals (χωρίς strict)
  128. function leak() {
  129.   x = 10;
  130. }
  131. leak();
  132. x;                    // 10 (global pollution)
  133.  
  134. // 24. JSON δεν υποστηρίζει undefined
  135. JSON.stringify({ a: undefined }); // "{}"
  136.  
  137. // 25. BONUS – Το απόλυτο WTF
  138. [] == [];             // false
  139. [] == ![];            // true
  140.  
Advertisement