• Stars
    star
    281
  • Rank 147,023 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Worst Minesweeper πŸ’£ Ever

JavaScript Equality Table Game

…or why you should prefer the === operator.


Build Status

Screenshot

Screenshot

About ==

The == or loose equality operator (and its counterpart !=) in JavaScript tries to save the user from having to explicitly convert (cast) values to a common type to make comparisons, so, for example, "5" == 5 implicitly converts (coerces) the string "5" to a number, so the comparison 'just works'. Without loose equality, the same comparison would need to be expressed as either Number("5") == 5 or "5" == String(5), or, at the shortest, +"5" == 5 to be true.

The general principle behind having implicit type conversion is called weak typing, and it's useful to the degree that it makes code more terse, but the flip side is that the implicit conversion rules are basically guesswork about what the user would expect, and, as such, can guess wrong and lead to unexpected results.

== doesn't check for truthiness or falsiness

Values that convert to either true or false are called truthy or falsy; for example, 0 is falsy because !!0 or Boolean(0) result in false. Other examples of falsy values are empty strings, null and undefined. Meanwhile, all objects (except document.all) are truthy, so !![] (array object converted to boolean) results in true.

One would reasonably expect that being truthy also implies == true and falsy implies == false, but that's not the case: [] is truthy, but [] == true is actually false.

== breaks transitivity

Transitivity means that if A equals B and B equals C, then A should equal C, but this is not always true with ==; for example, '' == 0, and 0 == '0', but '' != '0'.

=== isn't a panacea for typing issues

Tripple equals or strict equality checking rules are much simpler than ==; objects are compared by identity and primitives by value (roughly speaking), but it's still possible to create subtle type-related error conditions by forgetting to convert the compared values to the same type. For example, the user might compare "1" === 2, intending to compare numbers, and the resulting false would suggest that the comparison is working correctly, even though "2" === 2 would fail.

A language like TypeScript would catch these issues, because static typing follows the fail-fast design principle, while dynamic typing ultimately follows garbage in, garbage out – the responsibility is on the user to make sure that the comparison is sound.

Trivia

Brendan Eich was asked to add the loose equality checking rules by a coworker in Netscape and considers it a mistake.[citation needed]

Motivation

The initial reason to make this game was to try out state management with immer-wieder, but it's also to demonstrate that the == rules are easy to get wrong even if you feel like you're familiar with them. It's in response to claims like this one by the well-known author getify:

However, implicit coercion is a mechanism that can be learned, and moreover should be learned by anyone wishing to take JavaScript programming seriously. Not only is it not confusing once you learn the rules, it can actually make your programs better! The effort is well worth it.

If the implicit coercion rules were as non-confusing as claimed by getify, most experienced JavaScript users would be able to get close to perfect scores in this game, but there are many reports about giving it a serious attempt and being surprised by the poor results, including from seasoned users.

Emojis

The game uses emojis; your system and browser should preferably support color fonts and have an emoji font like EmojiOne or Noto Color Emoji installed for the emojis to display properly. If not, the game will provide fallback SVG images from emojitwo (using emoji-extractor).

Build

npm i
npm run build # or: npm run start

Adding a translation

The translation string template is translations/en-US.json, and new translations need to be registered in translationData.js.

Tools used

License

MIT

Author

slikts <[email protected]>

Other web-related games

More Repositories

1

concurrency-glossary

πŸ¦‘ Informal definitions of terms used in concurrency modeling
HTML
314
star
2

tooling

🧰 Up-to-date list of JavaScript and TypeScript tooling resources
HTML
235
star
3

tuplerone

Tuples and value objects for JavaScript 🀷
TypeScript
54
star
4

promiseproxy

Promisify callback-style APIs with ES2015 Proxy 🐳
JavaScript
46
star
5

queueable

Convert streams to async βŒ› iterables ➰
TypeScript
46
star
6

gh-minimap

Source code πŸ’» minimap πŸ—ΊοΈ extension for GitHub πŸ™ˆ
JavaScript
10
star
7

sensfinder

Tool to help finding the best sensitivity for CS
CSS
9
star
8

vardadienas

Vārda dienu kalendāra dati πŸ‡±πŸ‡»
TypeScript
8
star
9

wtmap

Chrome extension that adds plane icons and centering on player to the War Thunder browser tactical map
JavaScript
8
star
10

circulator

Simple, generator-based circular iterator 🐍
TypeScript
7
star
11

react-matter-js

🌠 React adapter for the Matter.js physics engine
TypeScript
7
star
12

latvian-grammar

Latvian grammar library
JavaScript
7
star
13

symbola

Cooking with symbols 🍳
TypeScript
7
star
14

deepproxy

Recursive ES2015 Proxy
TypeScript
5
star
15

repython

Python
5
star
16

nelabs.dev

JavaScript
3
star
17

fetchpoeitems

JavaScript
3
star
18

mangoext

🐰 A revolution in mango technology
JavaScript
3
star
19

react-default-memo

πŸ“ Proof of concept for deeply memoizing React components by default
JavaScript
3
star
20

promiseproxy-node

ES2015 Proxy based wrapper for promisifying Node.js 6 API
JavaScript
3
star
21

promiseproxy-chrome

Lightweight Proxy-based promisified Chrome API wrapper
JavaScript
3
star
22

factorio-data

Factorio prototype data in JSON format
JavaScript
2
star
23

rpftool

Automatically exported from code.google.com/p/rpftool
C#
2
star
24

batoto-scraper

PHP
2
star
25

vds

Vārdadienas
JavaScript
2
star
26

rxjs-rollup-example

The operators don't get bundled
JavaScript
2
star
27

emojitorio

Lua
1
star
28

dotacharts

Simple charts from Dota 2 match replays
Python
1
star
29

pargimeni

HTML
1
star
30

smoosh-db

TypeScript
1
star
31

ciba

TypeScript
1
star
32

dotjs

JavaScript
1
star
33

code-examples

Poor Quality Code Examples
JavaScript
1
star
34

soundboard

Soundboard app implemented with NodeGui
TypeScript
1
star
35

yarn-plugins

1
star
36

_slikts.github.com

anti-annoyances
1
star
37

ddnsupdate

Python
1
star
38

lib-bones

TypeScript
1
star
39

sri-extract-repro

JavaScript
1
star
40

no-jquery

HTML
1
star
41

esnext-generic-iteration

Generic iteration methods for ES.next
JavaScript
1
star
42

unreaddit

A Chrome extension to highlight unread reddit comments.
JavaScript
1
star