Skip to content

Instantly share code, notes, and snippets.

@artalar
Forked from MichalZalecki/wtf.js
Last active February 4, 2019 09:25

Revisions

  1. artalar revised this gist Apr 14, 2018. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions wtf.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    /* VT100 terminal reset (<ESC>c) */
    /* VT100 terminal reset (<ESC>c) */

    console.log('\033c');

    @@ -149,9 +149,9 @@ console.log('\033c');
    //// true

    /**/ new String('wtf');
    /* { '0': 'w',
    '1': 't',
    '2': 'f' } */
    /* { '0': 'w',
    '1': 't',
    '2': 'f' } */

    /**/ new String('wtf').toString();
    //// 'wtf'
    @@ -204,14 +204,14 @@ console.log('\033c');
    //// 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) */
    /* 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) */
  2. artalar revised this gist Apr 14, 2018. 1 changed file with 122 additions and 122 deletions.
    244 changes: 122 additions & 122 deletions wtf.js
    Original file line number Diff line number Diff line change
    @@ -4,206 +4,206 @@ console.log('\033c');

    /* numbers comparations */

    /* > */ '2' == 2;
    // true
    /**/ '2' == 2;
    //// true

    /* > */ '2' === 2;
    // false
    /**/ '2' === 2;
    //// false

    /* > */ [2] == 2;
    // true
    /**/ [2] == 2;
    //// true

    /* > */ [] + [];
    // ''
    /**/ [] + [];
    //// ''

    /* > */ [] == [];
    // false
    /**/ [] == [];
    //// false

    /* > */ typeof [];
    // 'object'
    /**/ typeof [];
    //// 'object'

    /* > */ [] == ![];
    // true
    /**/ [] == ![];
    //// true

    /* > */ +[] == +![];
    // true
    /**/ +[] == +![];
    //// true

    /* null comparation */

    /* > */ 0 > null;
    // false
    /**/ 0 > null;
    //// false

    /* > */ 0 >= null;
    // true
    /**/ 0 >= null;
    //// true

    /* > */ 0 == null;
    // false
    /**/ 0 == null;
    //// false

    /* > */ 0 <= null;
    // true
    /**/ 0 <= null;
    //// true

    /* > */ 0 < null;
    // false
    /**/ 0 < null;
    //// false

    /* > */ typeof null;
    // 'object'
    /**/ typeof null;
    //// 'object'

    /* > */ null instanceof Object;
    // false
    /**/ null instanceof Object;
    //// false

    /* math */

    /* > */ 999999999999999;
    // 999999999999999
    /**/ 999999999999999;
    //// 999999999999999

    /* > */ 9999999999999999;
    // 10000000000000000
    /**/ 9999999999999999;
    //// 10000000000000000

    /* > */ -9999999999999999;
    // -10000000000000000
    /**/ -9999999999999999;
    //// -10000000000000000

    /* > */ 0.1 + 0.2 == 0.3;
    // false
    /**/ 0.1 + 0.2 == 0.3;
    //// false

    /* > */ 0.1 + 0.2;
    // 0.30000000000000004
    /**/ 0.1 + 0.2;
    //// 0.30000000000000004

    /* > */ 3 > 2 > 1;
    // false
    /**/ 3 > 2 > 1;
    //// false

    /* > */ 3 > 2 >= 1;
    // true
    /**/ 3 > 2 >= 1;
    //// true

    /* > */ '2' + 1;
    // '21'
    /**/ '2' + 1;
    //// '21'

    /* > */ '2' - 1;
    // 1
    /**/ '2' - 1;
    //// 1

    /* > */ '2' - -1;
    // 3
    /**/ '2' - -1;
    //// 3

    /* > */ 1/0;
    // Infinity
    /**/ 1/0;
    //// Infinity

    /* > */ typeof Infinity;
    // 'number'
    /**/ typeof Infinity;
    //// 'number'

    /* > */ 0 === -0;
    // true
    /**/ 0 === -0;
    //// true

    /* > */ 1/0;
    // Infinity
    /**/ 1/0;
    //// Infinity

    /* > */ 1/-0;
    // -Infinity
    /**/ 1/-0;
    //// -Infinity

    /* > */ Infinity == -Infinity;
    // false
    /**/ Infinity == -Infinity;
    //// false

    /* > */ Number.MAX_VALUE;
    // 1.7976931348623157e+308
    /**/ Number.MAX_VALUE;
    //// 1.7976931348623157e+308

    /* > */ 0 - 1;
    // -1
    /**/ 0 - 1;
    //// -1

    /* > */ Number.MIN_VALUE < 0;
    // false
    /**/ Number.MIN_VALUE < 0;
    //// false

    /* > */ Number.MIN_VALUE;
    // 5e-324>
    /**/ Number.MIN_VALUE;
    //// 5e-324>

    /* > */ Math.max(1,2,3);
    // 3
    /**/ Math.max(1,2,3);
    //// 3

    /* > */ Math.min(1,2,3);
    // 1
    /**/ Math.min(1,2,3);
    //// 1

    /* > */ Math.max() > Math.min();
    // false
    /**/ Math.max() > Math.min();
    //// false

    /* > */ Math.max();
    // -Infinity
    /**/ Math.max();
    //// -Infinity

    /* > */ Math.min();
    // Infinity
    /**/ Math.min();
    //// Infinity

    /* string */

    /* > */ 'wtf' instanceof String;
    // false
    /**/ 'wtf' instanceof String;
    //// false

    /* > */ typeof 'wtf';
    // 'string'
    /**/ typeof 'wtf';
    //// 'string'

    /* > */ typeof String('wtf');
    // 'string'
    /**/ typeof String('wtf');
    //// 'string'

    /* > */ String('wtf') === 'wtf';
    // true
    /**/ String('wtf') === 'wtf';
    //// true

    /* > */ String('wtf') === new String('wtf');
    // false
    /**/ String('wtf') === new String('wtf');
    //// false

    /* > */ String('wtf') == new String('wtf');
    // true
    /**/ String('wtf') == new String('wtf');
    //// true

    /* > */ new String('wtf');
    /**/ new String('wtf');
    /* { '0': 'w',
    '1': 't',
    '2': 'f' } */

    /* > */ new String('wtf').toString();
    // 'wtf'
    /**/ new String('wtf').toString();
    //// 'wtf'

    /* > */ 'wft' + 1;
    // 'wft1'
    /**/ 'wft' + 1;
    //// 'wft1'

    /* > */ 'wft' - 1;
    // NaN
    /**/ 'wft' - 1;
    //// NaN

    /* NaN */

    /* > */ typeof NaN;
    // 'number'
    /**/ typeof NaN;
    //// 'number'

    /* > */ typeof 1138;
    // 'number'
    /**/ typeof 1138;
    //// 'number'

    /* > */ 1138 == 1138;
    // true
    /**/ 1138 == 1138;
    //// true

    /* > */ NaN == NaN;
    // false
    /**/ NaN == NaN;
    //// false

    /* > */ isNaN('wft' - 1);
    // true
    /**/ isNaN('wft' - 1);
    //// true

    /* boolean math */

    /* > */ true + false;
    // 1
    /**/ true + false;
    //// 1

    /* > */ true + true == true;
    // false
    /**/ true + true == true;
    //// false

    /* construct function */

    /* > */ new 0xff.constructor.constructor('console.error("WTF")')();
    // WTF
    /**/ new 0xff.constructor.constructor('console.error("WTF")')();
    //// WTF

    /* > */ new Function('console.error("WTF")')();
    // WTF
    /**/ new Function('console.error("WTF")')();
    //// WTF

    /* typeof/instanceof */

    /* > */ Array instanceof Array;
    // false
    /**/ Array instanceof Array;
    //// false

    /* > */ new Array instanceof Array;
    // true
    /**/ new Array instanceof Array;
    //// true

    /* > */ Math instanceof Math;
    /**/ 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)
  3. artalar revised this gist Apr 14, 2018. 1 changed file with 126 additions and 147 deletions.
    273 changes: 126 additions & 147 deletions wtf.js
    Original file line number Diff line number Diff line change
    @@ -4,227 +4,207 @@ console.log('\033c');

    /* numbers comparations */

    > '2' == 2
    true
    /* > */ '2' == 2;
    // true

    > '2' === 2
    false
    /* > */ '2' === 2;
    // false

    > [2] == 2
    true
    /* > */ [2] == 2;
    // true

    > [] + []
    ''
    /* > */ [] + [];
    // ''

    > [] == []
    false
    /* > */ [] == [];
    // false

    > typeof []
    'object'
    /* > */ typeof [];
    // 'object'

    > [] == ![]
    true
    /* > */ [] == ![];
    // true

    > +[] == +![]
    true
    /* > */ +[] == +![];
    // true

    /* null comparation */

    > 0 > null
    false
    /* > */ 0 > null;
    // false

    > 0 >= null
    true
    /* > */ 0 >= null;
    // true

    > 0 == null
    false
    /* > */ 0 == null;
    // false

    > 0 <= null
    true
    /* > */ 0 <= null;
    // true

    > 0 < null
    false
    /* > */ 0 < null;
    // false

    > typeof null
    'object'
    /* > */ 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
    /* > */ null instanceof Object;
    // false

    /* math */

    > 999999999999999
    999999999999999
    /* > */ 999999999999999;
    // 999999999999999

    > 9999999999999999
    10000000000000000
    /* > */ 9999999999999999;
    // 10000000000000000

    > -9999999999999999
    -10000000000000000
    /* > */ -9999999999999999;
    // -10000000000000000

    > 0.1 + 0.2 == 0.3
    false
    /* > */ 0.1 + 0.2 == 0.3;
    // false

    > 0.1 + 0.2
    0.30000000000000004
    /* > */ 0.1 + 0.2;
    // 0.30000000000000004

    > 3 > 2 > 1
    false
    /* > */ 3 > 2 > 1;
    // false

    > 3 > 2 >= 1
    true
    /* > */ 3 > 2 >= 1;
    // true

    > '2' + 1
    '21'
    /* > */ '2' + 1;
    // '21'

    > '2' - 1
    1
    /* > */ '2' - 1;
    // 1

    > '2' - -1
    3
    /* > */ '2' - -1;
    // 3

    > 1/0
    Infinity
    /* > */ 1/0;
    // Infinity

    > typeof Infinity
    'number'
    /* > */ typeof Infinity;
    // 'number'

    > 0 === -0
    true
    /* > */ 0 === -0;
    // true

    > 1/0
    Infinity
    /* > */ 1/0;
    // Infinity

    > 1/-0
    -Infinity
    /* > */ 1/-0;
    // -Infinity

    > Infinity == -Infinity
    false
    /* > */ Infinity == -Infinity;
    // false

    Number.MAX_VALUE
    1.7976931348623157e+308
    /* > */ Number.MAX_VALUE;
    // 1.7976931348623157e+308

    > 0 - 1
    -1
    /* > */ 0 - 1;
    // -1

    > Number.MIN_VALUE < 0
    false
    /* > */ Number.MIN_VALUE < 0;
    // false

    > Number.MIN_VALUE
    5e-324>
    /* > */ Number.MIN_VALUE;
    // 5e-324>

    > Math.max(1,2,3)
    3
    /* > */ Math.max(1,2,3);
    // 3

    > Math.min(1,2,3)
    1
    /* > */ Math.min(1,2,3);
    // 1

    > Math.max() > Math.min()
    false
    /* > */ Math.max() > Math.min();
    // false

    > Math.max()
    -Infinity
    /* > */ Math.max();
    // -Infinity

    > Math.min()
    Infinity
    /* > */ Math.min();
    // Infinity

    /* string */

    > 'wtf' instanceof String
    false
    /* > */ 'wtf' instanceof String;
    // false

    > typeof 'wtf'
    'string'
    /* > */ typeof 'wtf';
    // 'string'

    > typeof String('wtf')
    'string'
    /* > */ typeof String('wtf');
    // 'string'

    > String('wtf') === 'wtf'
    true
    /* > */ String('wtf') === 'wtf';
    // true

    > String('wtf') === new String('wtf')
    false
    /* > */ String('wtf') === new String('wtf');
    // false

    > String('wtf') == new String('wtf')
    true
    /* > */ String('wtf') == new String('wtf');
    // true

    > new String('wtf')
    { '0': 'w',
    /* > */ new String('wtf');
    /* { '0': 'w',
    '1': 't',
    '2': 'f' }
    '2': 'f' } */

    > new String('wtf').toString()
    'wtf'
    /* > */ new String('wtf').toString();
    // 'wtf'

    > 'wft' + 1
    'wft1'
    /* > */ 'wft' + 1;
    // 'wft1'

    > 'wft' - 1
    NaN
    /* > */ 'wft' - 1;
    // NaN

    /* NaN */

    > typeof NaN
    'number'
    /* > */ typeof NaN;
    // 'number'

    > typeof 1138
    'number'
    /* > */ typeof 1138;
    // 'number'

    > 1138 == 1138
    true
    /* > */ 1138 == 1138;
    // true

    > NaN == NaN
    false
    /* > */ NaN == NaN;
    // false

    > isNaN('wft' - 1)
    true
    /* > */ isNaN('wft' - 1);
    // true

    /* boolean math */

    > true + false
    1
    /* > */ true + false;
    // 1

    > true + true == true
    false
    /* > */ true + true == true;
    // false

    /* construct function */

    > new 0xff.constructor.constructor('console.error("WTF")')()
    WTF
    /* > */ new 0xff.constructor.constructor('console.error("WTF")')();
    // WTF

    > new Function('console.error("WTF")')()
    WTF
    /* > */ new Function('console.error("WTF")')();
    // WTF

    /* typeof/instanceof */

    > Array instanceof Array
    false
    /* > */ Array instanceof Array;
    // false

    > new Array instanceof Array
    true
    /* > */ new Array instanceof Array;
    // true

    > Math instanceof Math
    TypeError: Expecting a function in instanceof check, but got #<Object>
    /* > */ 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)
    @@ -234,5 +214,4 @@ TypeError: Expecting a function in instanceof check, but got #<Object>
    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)
    >
    at emitKey (readline.js:1096:12) */
  4. @MichalZalecki MichalZalecki revised this gist Jun 2, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions wtf.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    /* VT100 terminal reset (<ESC>c) */

    console.log('\033c');

    /* numbers comparations */
  5. @MichalZalecki MichalZalecki created this gist Jun 2, 2015.
    236 changes: 236 additions & 0 deletions wtf.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,236 @@
    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)
    >