Skip to content

Instantly share code, notes, and snippets.

@springheeledjak
Last active May 25, 2024 16:51
Show Gist options
  • Select an option

  • Save springheeledjak/64e23a9f5b02b9405c0f to your computer and use it in GitHub Desktop.

Select an option

Save springheeledjak/64e23a9f5b02b9405c0f to your computer and use it in GitHub Desktop.
Fuck you, JavaScript.

TL;DR: type coercion is the devil.

Metadata

$ node -v
v0.12.2
$ node
> null < 1
true
> null > -1
true
> null < 0
false
> null > 0
false
> null == 0
false
> null + 0
0
$ node
> undefined < 1
false
> undefined > -1
false
> undefined < 0
false
> undefined > 0
false
> undefined == 0
false
> undefined == null
true
$ node
> obj = {}; obj++; obj
NaN
> obj = {}; obj--; obj
NaN
> obj = {}; obj += 1
'[object Object]1'
> obj = {}; obj -= 1
NaN
$ node
> arr = []; arr++; arr
1
> arr = []; arr--; arr
-1
> arr = []; arr += 1
'1'
> arr = []; arr -= 1
-1
> arr = []; arr += []
''
$ node
> '' == 0
true
> str = ''; str += 1
'1'
> str = ''; str -= 1
-1
@bukowa
Copy link
Copy Markdown

bukowa commented May 25, 2024

Fuck You Javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment