denysdovhan /wtfjs
🤪 A list of funny and tricky JavaScript examples
★ 37,693⑂ 2,673👁 564⑃ 202● 123▤ 25
+0
日增长
+6
周增长
37,693
stars
2,673
forks
564
watchers
202
prs
123
issues
25
releases
README
What the f\ck JavaScript?
[![WTFPL 2.0][license-image]][license-url]
[![NPM version][npm-image]][npm-url]
[![Patreon][patreon-image]][patreon-url]
[![Buy Me A Coffee][bmc-image]][bmc-url]
A list of funny and tricky JavaScript examples
JavaScript is a great language. It has a simple syntax, large ecosystem and, what is most important, a great community.
At the same time, we all know that JavaScript is quite a funny language with tricky parts. Some of them can quickly turn our everyday job into hell, and some of them can make us laugh out loud.
The original idea for WTFJS belongs to Brian Leroux. This list is highly inspired by his talk “WTFJS” at dotJS 2012:
Node Packaged Manuscript
You can install this handbook using npm. Just run:
$ npm install -g wtfjs
You should be able to run wtfjs at the command line now. This will open the manual in your selected $PAGER. Otherwise, you may continue reading on here.
The source is available here:
Translations
Currently, there are these translations of wtfjs:
- 中文
- हिंदी
- Français
- Português do Brasil
- Polski
- Italiano
- 한국어
[Help translating to your language][tr-request]
[tr-request]: https://github.com/denysdovhan/wtfjs/blob/master/CONTRIBUTING.mdtranslations
Note: Translations are maintained by their translators. They may not contain every example, and existing examples may be outdated.
Table of Contents
- 💪🏻 Motivation
- ✍🏻 Notation
- 👀 Examples
- [[] is equal ![]](-is-equal-)
- [true is not equal ![], but not equal [] too](true-is-not-equal--but-not-equal--too)
- true is false
- baNaNa
- NaN is not a NaN
- Object.is() and === weird cases
- It's a fail
- [[] is truthy, but not true](-is-truthy-but-not-true)
- null is falsy, but not false
- document.all is an object, but it is undefined
- Minimal value is greater than zero
- function is not a function
- Adding arrays
- Trailing commas in array
- Array equality is a monster
- undefined and Number
- parseInt is a bad guy
- Math with true and false
- HTML comments are valid in JavaScript
- NaN is ~~not~~ a number
- [[] and null are objects](-and-null-are-objects)
- Magically increasing numbers
- Precision of 0.1 + 0.2
- Patching numbers
- Comparison of three numbers
- Funny math
- Addition of RegExps
- Strings aren't instances of String
- Calling functions with backticks
- Call call call
- A constructor property
- Object as a key of object's property
- Accessing prototypes with __proto__
- ${{Object}}
- Destructuring with default values
- Dots and spreading
- Labels
- Nested labels
- Insidious try..catch
- Is this multiple inheritance?
- A generator which yields itself
- A class of class
- Non-coercible objects
- Tricky arrow functions
- Arrow functions can not be a constructor
- arguments and arrow functions
- Tricky return
- Chaining assignments on object
- Accessing object properties with arrays
- Number.toFixed() display Top issues
#329Insane Proxy hack3 comments · 2024-08-17#347The automated release is failing 🚨2 comments · 2026-07-03#341Character data interpreted in XHTML2 comments · 2025-08-13#326A script to take you to a random example on the readme for this repo :)2 comments · 2024-06-25#316Explanation of first example is wrong2 comments · 2023-09-01#208Constructor Returns Subclass of Constructed Class: Extra Newness v2: Deceptively Sensical Looking2 comments · 2021-05-06#337`for..in` iterating array indices: `string`, Not just `number`0 comments · 2025-02-06#327Direct call and indirect call of `eval` behave differently1 comments · 2024-06-26
Discussions
#331method `this` binding is lost in _some_ expressions0 comments · 2024-10-15#328Apparently postfix operators converts the old value to number as well0 comments · 2024-07-10#325Accessing a number using the array operator e.g. 1[0] returns undefined1 comments · 2024-06-10#323Bitwise &0 comments · 2024-02-21#318some() and every() on empty array0 comments · 2023-11-19#260Symbol is a constructor but not a constructor0 comments · 2022-05-31#214Wording in "Why you should use semicolons" can be improved1 comments · 2021-06-22#183Welcome to wtfjs Discussions!1 comments · 2021-02-05
Latest release
v1.22.8 v1.22.8 2022-09-301.22.8 (2022-09-30) Bug Fixes broken link in zh-cn translation (278) (c6f8310)