r/loljs • • Aug 10 '14

Hold your horses! ['10','10','10','10'].map(parseInt) yields [10, NaN, 2, 3]

0 Upvotes

r/loljs • • Jan 13 '20

Does this nightmare of a language always execute things in the wrong order?

Post image
5 Upvotes

r/loljs • • Jan 08 '22

typeof '' === String

0 Upvotes

'string' was what I was looking for...


r/loljs • • Mar 31 '16

Math.wtf

0 Upvotes

Math.max() -Infinity Math.min() Infinity

Shouldn't that be reverse?


r/loljs • • Jan 24 '17

let r = /abc/g; console.log(r.test('abc'), r.test('abc')); // true false

8 Upvotes
const REGEX = /abc/g
REGEX.test('abc');
> true
REGEX.test('abc'));
> false

r/loljs • • Mar 28 '16

When is not a number a number?

0 Upvotes
$: node
> typeof(NaN)
'number'
>

r/loljs • • May 23 '18

[]==[] and []===[] return false.

10 Upvotes

...Also when I concantenate these two HTMLCollections their "length" value is iterated through so I get a TypeError when my iteration tries to treat the length integer like an HTML element. I thought programming/scripting languages were supposed to be logical!

btw I found this subreddit because I once came across /r/lolphp while being pissed off at PHP's nonexistent stack trace (fixed by using debug_backtrace()) and I replaced the "php" with "js".


r/loljs • • Apr 29 '17

big numbers are equal

5 Upvotes
>100000000000000000==99999999999999999 
<true

the scary part, === doesn't even notice this

>100000000000000000===99999999999999999 
<true

and if you try a string:

>100000000000000000=="99999999999999999"
<true

but at least, it notices that 1 is a string and the other a number:

>100000000000000000==="99999999999999999"
<false

finally! some sanity

and in case you wonder, "use strict" makes no difference.


r/loljs • • Oct 25 '19

async/await is new, why give it PHP-style coercion semantics?

Post image
11 Upvotes

r/loljs • • Sep 02 '16

Adding an Object in an Object creates a key based on the variable name

Thumbnail jsfiddle.net
5 Upvotes

r/loljs • • Aug 26 '14

Node.js leadership

Post image
21 Upvotes

r/loljs • • Nov 17 '14

There second argument in substring and substr has different meanings

Thumbnail
stackoverflow.com
3 Upvotes

r/loljs • • Jul 27 '14

Defeating infinity: parseInt(1 / 0, 19) == 18

Thumbnail
ctmmc.net
5 Upvotes

r/loljs • • May 27 '15

var a = Object.create(null)

13 Upvotes
typeof a // --> "object"
a instanceof Object // --> false

r/loljs • • Mar 30 '18

This is from latest is-odd library debate

Thumbnail rextester.com
7 Upvotes

r/loljs • • Mar 27 '14

"0"==false is true, but if("0"){/* executes */}

Thumbnail
reddit.com
8 Upvotes

r/loljs • • Aug 03 '15

Node.JS "best practices" . . . or a long list of reasons why JS is poorly suited for async operations?

Thumbnail
justbuildsomething.com
8 Upvotes

r/loljs • • Sep 20 '17

Array.from({lol: "js"}) returns empty array

9 Upvotes

Converting non-iterable objects (or numbers) to arrays using Array.from silently returns an empty array. That is, of course, unless you pass something like undefined or null. Then you get the descriptive error TypeError: V is null (Firefox, not really a loljs).

Forgot to define Symbol.iterator on your makeshift iterator to return itself? Don't even think about getting any error messages like you do with for-of. Array.from just gives you an empty array and confusion.

Hell, javascript technically doesn't even require iterators to define Symbol.iterator like Python does for __iter__. Searching around, several js libraries meant to remedy the absent standard library support for working with iterators don't bother with Symbol.iterator when creating or working with iterators.

Anyway, not really a surprise when it comes to js I guess. Raising an error for null and silently doing the wrong thing for other bad values is a classic javascript tactic to keep you on your toes. Still, never heard anyone complain about this particular function before, and it annoyed me, so I thought I'd share.


r/loljs • • Jun 26 '22

Number properties are silently lost/discarded/undefined

Post image
18 Upvotes

r/loljs • • Oct 20 '16

Github is down? 1 + 2 = 404

Thumbnail
twitter.com
33 Upvotes

r/loljs • • Sep 27 '17

Don't use "new Array", or use "Array" with a number, or use Array at all, but JavaScript arrays are great, even though JavaScript doesn't really have arrays

Thumbnail
tech.io
12 Upvotes

r/loljs • • Jun 01 '21

NaN is iterable

19 Upvotes
> Array.from(undefined)
< VM528:1 Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.from (<anonymous>)
    at <anonymous>:1:7
(anonymous) @ VM528:1


> Array.from(null)
< VM596:1 Uncaught TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))
    at Function.from (<anonymous>)
    at <anonymous>:1:7
(anonymous) @ VM596:1


> Array.from(NaN)
< []

r/loljs • • Jul 17 '14

JavaScript Jeopardy

Thumbnail
twitter.com
6 Upvotes

r/loljs • • May 07 '17

The incomparable JavaScript

Thumbnail stedolan.net
6 Upvotes

r/loljs • • Aug 24 '17

How bad could it be, right? Oops.

Thumbnail news.ycombinator.com
7 Upvotes