Skip to content

Instantly share code, notes, and snippets.

@shapkarin
Last active March 11, 2022 08:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shapkarin/b3fbeaca95ef69df177b to your computer and use it in GitHub Desktop.
Save shapkarin/b3fbeaca95ef69df177b to your computer and use it in GitHub Desktop.
curiosity.js
/*
. .-.
| `-.
`-' `-'
*/
[] + {}
// "[object Object]"
{} + []
// 0
[] - {}
// NaN
{} - []
// -0
1 + true
// 2
1 + []
// "1"
true + []
// "true"
true + ''
// "true"
[] == ''
// true
0 == ''
// true
0 == []
// true
[] == ![]
// true
Math.cos('') === 1
// true
Math.cos([]) === 1
// true
0 == '0'
// true
[] == '0'
// false
[] == ''
// true
[...Array(2)] == ','
// true
new Array([],null,undefined) == ',,'
// true
![] == 1
// false
![] == 0
// true
!![] == 1
// true
1 === 1.0
// true
1 === 1.9
// false
1 === 1.00000000000000009
// true
'a' === 'a'
// true
'a' === new String('a')
// false
'a' === new String('a').toString()
// true
var a = 0.1,
b = 0.2,
c = a + b
c === 0.3
// false
var x = 1
x += 1
// 2
var x = 1
x-=-!''
// 2
var x = 1
x-=-Math.cos([])
// 2
Math.max() > Math.min()
// false
Number.MIN_VALUE < 0
// false
typeof NaN
// "number"
typeof []
// "object"
typeof {}
// "object"
typeof null
// "object"
NaN === NaN
// false
NaN == NaN
// false
isNaN(NaN)
// true
isNaN(null)
// false
isNaN(undefined)
// true
isNaN([])
// false
isNaN({})
// true
[1,2,3] === [1,2,3]
// false
[1,2,3] == [1,2,3]
// false
JSON.stringify([1,2,3]) === JSON.stringify([1,2,3])
// true
[1, 2, 3] + [4, 5, 6]
// "1,2,34,5,6"
0..toString()
// "0"
0 .toString()
// "0"
[].toString()
// ""
+new Date()
// 1411663624535
+new Date() === Number(new Date)
// true
+new Date() === (new Date()).getTime()
// true
+[]
// 0
+[] === 0 + []
// false
0 + []
// "0"
typeof (0 + new Date())
// "string"
parseInt("1.let's see")
// NaN
parseFloat("1.let's see")
// 1
parseFloat('123.321try')
// 123.321
parseFloat('123.try321')
// 123
parseInt(1 / 0, 19)
// 18
parseInt('xyz', 36)
// 44027
parseInt(['a1', [2, [3, [4]]]], 11)
// 111
parseInt('1') === parseFloat('1')
// true
parseInt('a1', 11) === parseFloat('a1', 11)
// false
Math.PI ^ 0
// 3
Math.PI ^ []
// 3
Math.PI << []
// 3
Math.PI >> []
// 3
~Math.PI
// -4
~~Math.PI
// 3
Math.PI - Math.PI % 1
// 3
['1', '7', '11'].map(parseInt)
// [1, NaN, 3]
Array(16).join('wat' - 1) + ' Batman!'
// "NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN Batman!"
;(![] + [])[+[]] +
(![] + [])[+!+[]] +
([![]] + [][[]])[+!+[] + [+[]]] +
(![] + [])[!+[] + !+[]]
// "fail"
('b' + 'a' + + 'a' + 'a').toLowerCase();
// "banana"
$=_=>`$=${$};$()`;$()
// "$=_=>`$=${$};$()`;$()"
console.log((undefined + undefined + "O").toUpperCase());
// NANO
console.log((undefined + "O").toUpperCase());
// UNDEFINEDO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment