Programming Languages Weird Quirks

22 views
Skip to first unread message

Clement

unread,
Apr 28, 2025, 4:34:52 AM4/28/25
to The Ring Programming Language
Javascript is full of quirks and surprising behaviors and here are some of the weirdest and most infamous quirks:

console.log(0 == "0");            // true (string "0" → number 0)
console.log(0 == []);             // true ([] → "" → 0)
console.log("0" == []);           // false ([] → "", "0" != "")
console.log("0" === []);          // false

console.log(NaN === NaN);         // false
console.log(null == undefined);   // true
console.log(null === undefined);  // false
console.log(typeof null);         // "object" (should be "null")

console.log([] + []);             // "" (empty string)
console.log([] + {});             // "[object Object]"
console.log({} + []);             // 0 (in some consoles due to parsing)

console.log(parseInt("123abc"));  // 123
console.log(parseInt("abc123"));  // NaN
console.log(parseInt("08"));      // 8 (octal interpretation in old browsers)

console.log(true + true);   // 2
console.log(true == 1);     // true
console.log(true === 1);    // false

console.log([1, 10, 2].sort());  // [1, 10, 2] (lexicographical order)
console.log([1, 10, 2].sort((a, b) => a - b));  // Fix: [1, 2, 10]

console.log(!!"hello");      // true
console.log(!!0);            // false

console.log("😂".length);    // 2
console.log("🤦♂️".length);  // 4

console.log(Math.min() > Math.max());  // true

if ("0") console.log("Truthy!");       // Runs
console.log("0" == false);             // true

let s = "hello";
s.concat(" world");
console.log(s);      // "hello" (unchanged)

console.log(JSON.stringify({ a: undefined, b: null }));  // '{"b":null}' undefiend disappear

console.log([1, 2, 3] == "1,2,3");  // true
Reply all
Reply to author
Forward
0 new messages