Skip to content

Instantly share code, notes, and snippets.

@markogresak
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save markogresak/cf5c35eb579b2cce8b69 to your computer and use it in GitHub Desktop.

Select an option

Save markogresak/cf5c35eb579b2cce8b69 to your computer and use it in GitHub Desktop.

Let's start with

== comparison table

Just wonderful transitiveness of equals operator

"" == 0 is true, 0 == "0" is true, but "" == "0" is false (by Felix Gessert on Quora)

Advanced math

Consistency? Nah, too mainstream.
> '10' - 5
5
> '10' + 5
'105'

Or

> 'a' + + 'b'
'aNaN'
> '10' + + '5'
'105'
> '10' + - '5'
'10-5'
Mathematically correct (sort of)
> 10 + - + - + - 5
5
> 10 + - + - + - - 5
15
To convert or not to convert?
> '10' + - + - + - '5'
'10-5'
> '10' + - + - + - '-5'
'105'
Adding 2 empty arrays returns empty string

[] + []''

Adding array and object returns string of object in array. (same as [{}].toString())

[] + {}'[object Object]'

If we flip those, we would expect same result, right... Right!?

{} + []0 Nope.

Return value of adding two empty objects is somehow, strangely, correct

{} + {}NaN

Mapping array of strings to parseInt

> arr = ['10', '10', '10'];
> arr.map(parseInt);
[10, NaN, 2]

Quotes

Comparing Java and JavaScript is like comparing ham and hamster.

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