{"id":26883966,"url":"https://github.com/ferreiratiago/js-wtf","last_synced_at":"2025-03-31T17:37:58.608Z","repository":{"id":196979914,"uuid":"91006159","full_name":"ferreiratiago/js-wtf","owner":"ferreiratiago","description":"Some of the weirdest things on JavaScript","archived":false,"fork":false,"pushed_at":"2017-05-21T19:00:48.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-09-28T13:57:49.992Z","etag":null,"topics":["array","destructuring-assignment","iife","javascript","lexical-grammar","math","number","operators","statistics","string","temporary-dead-zones","wtf"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ferreiratiago.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-05-11T17:28:47.000Z","updated_at":"2023-09-28T13:57:51.588Z","dependencies_parsed_at":null,"dependency_job_id":"59f5fd8c-eda8-4e16-b5cd-9f949e98b1ff","html_url":"https://github.com/ferreiratiago/js-wtf","commit_stats":null,"previous_names":["ferreiratiago/js-wtf"],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferreiratiago%2Fjs-wtf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferreiratiago%2Fjs-wtf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferreiratiago%2Fjs-wtf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferreiratiago%2Fjs-wtf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ferreiratiago","download_url":"https://codeload.github.com/ferreiratiago/js-wtf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246510064,"owners_count":20789282,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","destructuring-assignment","iife","javascript","lexical-grammar","math","number","operators","statistics","string","temporary-dead-zones","wtf"],"created_at":"2025-03-31T17:37:57.294Z","updated_at":"2025-03-31T17:37:58.601Z","avatar_url":"https://github.com/ferreiratiago.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# What the f** JavaScript\nThese are some of the weirdest things brought to us by JavaScript.\n\n* [Number](#number)\n* [Math](#math)\n* [Operators](#operators)\n* [String](#string)\n* [Array](#array)\n* [Immediately Invoked Function Expression](#immediately-invoked-function-expression)\n* [Lexical Grammar](#lexical-grammar)\n* [Statements](#statements)\n* [Destructuring](#destructuring)\n* [Temporary Dead Zones](#temporary-dead-zones)\n\n## [Number](https://github.com/ferreiratiago/js-wtf/blob/master/number.md)\n```js\nNumber('0.')    // 0\nNumber('.0')    // 0\nNumber('.')     // NaN\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/number.md#wtf)\n\n```js\nNumber({})      // NaN\nNumber([])      // 0\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/number.md#wtf-1)\n\n```js\nNumber(undefined)   // NaN\nNumber(null)        // 0\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/number.md#wtf-2)\n\n```js\nNumber('0O0')       // 0\nNumber('0X0')       // 0\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/number.md#wtf-3)\n\n```js\nNumber.MAX_VALUE \u003e 0;   //true\nNumber.MIN_VALUE \u003c 0;   //false\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/number.md#wtf-4)\n\n```js\n42.toFixed(2)       // SyntaxError: Invalid or unexpected token\n42. toFixed(2)      // SyntaxError: Unexpected identifier\n42 .toFixed(2)      // '42.00'\n42 . toFixed(2)     // '42.00'\n42.0.toFixed(2)     // '42.00'\n42..toFixed(2)      // '42.00'\n(42).toFixed(2)     // '42.00'\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/number.md#why-5)\n\n## [Math](https://github.com/ferreiratiago/js-wtf/blob/master/math.md)\n```js\nMath.max() \u003e Math.min()   // false\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/math.md#wtf)\n\n## [Operators](https://github.com/ferreiratiago/js-wtf/blob/master/operators.md)\n```js\n[] + {}     // '[object Object]'\n{} + []     // 0\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/operators.md#wtf)\n\n```js\ntrue + true === 2   // true\ntrue - true === 0   // true\ntrue === 1          // false\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/operators.md#wtf-1)\n\n```js\n0.1 + 0.2 === 0.3   // false\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/operators.md#wtf-2)\n\n```js\n1 \u003c 2 \u003c 3   // true\n3 \u003e 2 \u003e 1   // false\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/operators.md#wtf-3)\n\n```js\n'5' + 3     // '53'\n'5' - 3     // 2\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/operators.md#wtf-4)\n\n## [String](https://github.com/ferreiratiago/js-wtf/blob/master/string.md)\n```js\nString(-0)      // '0'\nNumber('-0')    // -0\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/string.md#wtf)\n\n```js\nString(null)        // 'null'\nString([null])      //  ''\n\nString(undefined)    // 'undefined'\nString([undefined])  //  ''\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/string.md#wtf-1)\n\n```js\nString({})      // '[object Object]'\nString([])      // ''\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/string.md#wtf-2)\n\n```js\nvar s = Symbol('Hello World')   // Symbol(Hello World)\n\nString(s)   // 'Symbol(Hello World)'\ns + ''      // TypeError: Cannot convert a Symbol value to a string\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/string.md#wtf-3)\n\n```js\nparseInt('15')              // 15\nparseInt('15 and more')     // 15\nparseInt('more and 15')     // NaN\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/string.md#wtf-4)\n\n```js\n(!+[]+[]+![]).length    // 9\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/string.md#wtf-5)\n\n## [Array](https://github.com/ferreiratiago/js-wtf/blob/master/array.md)\n```js\n[] == ![]   // true\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/array.md#wtf)\n\n```js\nArray.apply(null, Array(3))        // [ undefined, undefined, undefined ]\nArray.apply(null, [,,,])           // [ undefined, undefined, undefined ]\nArray.apply(null, {length : 3})    // [ undefined, undefined, undefined ]\nArray.apply(null, (a,b,c) =\u003e {})   // [ undefined, undefined, undefined ]\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/array.md#wtf-1)\n\n```js\n[10, 9, 8, 3, 2, 1, 0].sort() // [ 0, 1, 10, 2, 3, 8, 9 ]\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/array.md#wtf-2)\n\n## [Immediately Invoked Function Expression](https://github.com/ferreiratiago/js-wtf/blob/master/iife.md)\n```js\nfunction () { console.log('Hello World') }()       // SyntaxError: Unexpected token (\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/iife.md#wtf)\n\n```js\nfunction foo() { console.log('Hello World') }()  // SyntaxError: Unexpected token )\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/iife.md#wtf-1)\n\n```js\n!function () { console.log('Hello World') }()  // Hello World\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/iife.md#wtf-2)\n\n## [Lexical Grammar](https://github.com/ferreiratiago/js-wtf/blob/master/lexical-grammar.md)\n```js\nfunction foo() {\n    return\n        'Hello World';\n}\n\nfoo()   // undefined\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/lexical-grammar.md#lexical-grammar)\n\n## [Statements](https://github.com/ferreiratiago/js-wtf/blob/master/statements.md)\n```js\nswitch (42) {\n    default:\n        console.log('foo');\n    case 10:\n    case 20:\n        console.log('bar');\n        break;\n    case 30:\n        console.log('zed');\n        break;\n}\n// foo\n// bar\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/statements.md#wtf)\n\n```js\nfunction foo() {\n    try {\n        return 2\n    } finally {\n        return 3\n    }\n}\n\nfoo()   // 3\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/statements.md#wtf-1)\n\n## [Destructuring](https://github.com/ferreiratiago/js-wtf/blob/master/destructuring.md)\n```js\nfunction foo(x = {y: 10}, {y = 20} = {}) {\n    console.log(x.y, y);\n}\n\nfoo();                  // 10 20\nfoo({y: 30}, {y: 40});  // 30 40\nfoo({}, {});            // undefined 20\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/destructuring.md#wtf)\n\n## [Temporary Dead Zones](https://github.com/ferreiratiago/js-wtf/blob/master/tdz.md)\n```js\n(function(a = b, b) {\n\n}(undefined, 1));   // ReferenceError\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/tdz.md#wtf)\n\n```js\nlet b = 1;\n\n(function(a = b, b) {\n    console.log(a, b);\n}(undefined, 2));   // ReferenceError\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/tdz.md#wtf-1)\n\n```js\n{\n    typeof a;   // undefined\n    typeof b;   // ReferenceError\n\n    let b;\n}\n```\n[*Why?*](https://github.com/ferreiratiago/js-wtf/blob/master/tdz.md#wtf-2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fferreiratiago%2Fjs-wtf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fferreiratiago%2Fjs-wtf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fferreiratiago%2Fjs-wtf/lists"}