Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* VT100 terminal reset (<ESC>c) */
console.log('\033c');
/* numbers comparations */
> '2' == 2
true
> '2' === 2
false
> [2] == 2
true
> [] + []
''
> [] == []
false
> typeof []
'object'
> [] == ![]
true
> +[] == +![]
true
/* null comparation */
> 0 > null
false
> 0 >= null
true
> 0 == null
false
> 0 <= null
true
> 0 < null
false
> typeof null
'object'
> null instanceof Object
false
/* checking array type */
> {}.toString.call([])
'[object Array]'
> function FooBar() {}
undefined
> {}.toString.call(new FooBar)
'[object Object]'
> (new FooBar).constructor == Foo
false
> [] instanceof Array
true
> Array.isArray([])
true
/* math */
> 999999999999999
999999999999999
> 9999999999999999
10000000000000000
> -9999999999999999
-10000000000000000
> 0.1 + 0.2 == 0.3
false
> 0.1 + 0.2
0.30000000000000004
> 3 > 2 > 1
false
> 3 > 2 >= 1
true
> '2' + 1
'21'
> '2' - 1
1
> '2' - -1
3
> 1/0
Infinity
> typeof Infinity
'number'
> 0 === -0
true
> 1/0
Infinity
> 1/-0
-Infinity
> Infinity == -Infinity
false
Number.MAX_VALUE
1.7976931348623157e+308
> 0 - 1
-1
> Number.MIN_VALUE < 0
false
> Number.MIN_VALUE
5e-324>
> Math.max(1,2,3)
3
> Math.min(1,2,3)
1
> Math.max() > Math.min()
false
> Math.max()
-Infinity
> Math.min()
Infinity
/* string */
> 'wtf' instanceof String
false
> typeof 'wtf'
'string'
> typeof String('wtf')
'string'
> String('wtf') === 'wtf'
true
> String('wtf') === new String('wtf')
false
> String('wtf') == new String('wtf')
true
> new String('wtf')
{ '0': 'w',
'1': 't',
'2': 'f' }
> new String('wtf').toString()
'wtf'
> 'wft' + 1
'wft1'
> 'wft' - 1
NaN
/* NaN */
> typeof NaN
'number'
> typeof 1138
'number'
> 1138 == 1138
true
> NaN == NaN
false
> isNaN('wft' - 1)
true
/* boolean math */
> true + false
1
> true + true == true
false
/* construct function */
> new 0xff.constructor.constructor('console.error("WTF")')()
WTF
> new Function('console.error("WTF")')()
WTF
/* typeof/instanceof */
> Array instanceof Array
false
> new Array instanceof Array
true
> Math instanceof Math
TypeError: Expecting a function in instanceof check, but got #<Object>
at repl:1:18
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:203:10)
at Interface._line (readline.js:532:8)
at Interface._ttyWrite (readline.js:761:14)
at ReadStream.onkeypress (readline.js:100:10)
at ReadStream.emit (events.js:98:17)
at emitKey (readline.js:1096:12)
>
@garrows

This comment has been minimized.

garrows commented Jan 24, 2017

['a','b','c'][3,2,1] === 'b'

@fletom

This comment has been minimized.

fletom commented Feb 8, 2017

> [10, 9, 8, 3, 2, 1, 0].sort()
[ 0, 1, 10, 2, 3, 8, 9 ]
@cheezypoofs

This comment has been minimized.

cheezypoofs commented Feb 13, 2017

> '1' / '1'
1
> '1' * '1'
1
> '1' + '1'
'11'
@Mechazawa

This comment has been minimized.

Mechazawa commented May 24, 2017

>[1,2,3,4].map(foo => {bar: foo * 10})
[undefined, undefined, undefined, undefined]
>[1,2,3,4].map(foo => {bar: foo * 10, baz: foo})
Syntax error!
@djbarnwal

This comment has been minimized.

djbarnwal commented Jun 1, 2017

> '10' - 3
7

> '10' + 3
'103'
@JoeReid

This comment has been minimized.

JoeReid commented Jun 16, 2017

> ""*""
0

> ""**""
1
@mcdorli

This comment has been minimized.

mcdorli commented Jul 27, 2017

@JoeReid @dhiraj161298 @Mechazawa @cheezypoofs learn type conversion, it's well defined and none of this is uneypected behaviour. @fletom The sort function operates on strings, of course it sorts it like that. This whole list is made by someone, who clearly doesn't understand the language. Especially the 0.2 + 0.1 part. It works with bits, of course it isn't exact.

@scriptin

This comment has been minimized.

scriptin commented Aug 4, 2017

@mcdorli Well, indeed 0.2 + 0.1 works as IEEE 754 says, but you know what?

$ echo | awk '{ print 0.1 + 0.2 }'
0.3

Where is your god now lol?

And please stop being a "you just don't appreciate the good parts ™" type of jerk. These are bugs caused by messed up type conversion rules. Instead of learning this crap, you could have spent your time improving the world or something, you know.

@zeromus

This comment has been minimized.

zeromus commented Aug 5, 2017

@mcdorli perfect! this is a good reference for someone who doesn't understand the language. You clearly doesn't understand something yourself... the language of humans -- the sarcasm, that someone can title a file "wtf" without being genuinely baffled by it.

@FotoXe33

This comment has been minimized.

FotoXe33 commented Oct 2, 2017

// This, display: true, 1 => so the condition is TRUE and the object is FOUND.
console.log($(this).is(':checked') || $(this).is(':selected'), $('[display_condition="'+$(this).attr("name")+':'+$(this).val()+'"]').length);

// So that's true
if($(this).is(':checked') || $(this).is(':selected'))
$('[display_condition="'+$(this).attr("name")+':'+$(this).val()+'"]').show(); // No executed.... OMG WTF JS !!!!

True and found but can't execute this VERY COMPLEX instruction (a show(), oh my fucking god impossible !!!!).... Nice job.

@1mike12

This comment has been minimized.

1mike12 commented Oct 17, 2017

[1,2,3,4].map(foo => {bar: foo * 10})
[undefined, undefined, undefined, undefined]
[1,2,3,4].map(foo => {bar: foo * 10, baz: foo})
Syntax error!

that's because js is interpreting it as a function body, not a literal object. It thinks you're passing in the callback

function(foo){
    bar: foo*10, baz: foo
    //no return
}
@renatorib

This comment has been minimized.

renatorib commented Nov 16, 2017

> parseInt('1')
1

> parseInt('2')
2

> parseInt('3')
3

> ['1', '2', '3'].map(parseInt)
[1, NaN, NaN]

> ['3', '2', '1'].map(parseInt)
[3, NaN, 1]

> ['1', '2', '3'].map(v => parseInt(v))
[1, 2, 3]
@kfird214

This comment has been minimized.

kfird214 commented Dec 15, 2017

why those thing are not changing?
and why this problems are in all java-script engines out there?
is this on purpose?

@klaygomes

This comment has been minimized.

klaygomes commented Jan 13, 2018

['a','b','c'][3,2,1] === 'b'
//same as
['a','b','c'][(3,2,1)] === 'b'
//same as
const idx = 3,2,1;
['a','b','c'][idx] === 'b'
//that is same as
const idx = 1;
['a','b','c'][idx] === 'b'
@alexisllamas

This comment has been minimized.

alexisllamas commented Feb 2, 2018

@renatorib parseInt recibes a second parameter called base, and map send two params, the value and the index, so it's correct

@topikito

This comment has been minimized.

topikito commented Feb 23, 2018

> [] + {}
'[object Object]'
> {} + []
0
@adsingh14

This comment has been minimized.

adsingh14 commented Apr 7, 2018

Math.ceil(1.0000000000000001) // output = 1
Math.ceil(1.000000000000001) // output = 2
🙂

@Leblayd

This comment has been minimized.

Leblayd commented Jul 5, 2018

> '1' + '1' - '1' + '1' - '1' + '1' - '1'
1000
@thisisabdus

This comment has been minimized.

thisisabdus commented Aug 22, 2018

Few things could be explained and they are not at all WTFs. For example, 0.1 + 0.2 is not a WTF. You would get similar results in most of the language. And similarly, { } + [ ] >_<

Please watch this video on YouTube ( https://youtu.be/2pL28CcEijU ) before commenting anything here :)

@NicePixel

This comment has been minimized.

NicePixel commented Dec 11, 2018

3 > 2 > 1
false

3 > 2 >= 1
true
Interpreting from left to right, 3 > 2 evaluates to true.
The whole expression is false because (3 > 2) == true == 1 and hence 1 > 1 is false, but 1 >= 1 is true.

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