r/loljs • u/lukaseder • Aug 10 '14
r/loljs • u/phoborsh • Jan 13 '20
Does this nightmare of a language always execute things in the wrong order?
r/loljs • u/waiting4op2deliver • Jan 08 '22
typeof '' === String
'string' was what I was looking for...
r/loljs • u/igorim • Mar 31 '16
Math.wtf
Math.max() -Infinity Math.min() Infinity
Shouldn't that be reverse?
r/loljs • u/jonnyburger • Jan 24 '17
let r = /abc/g; console.log(r.test('abc'), r.test('abc')); // true false
const REGEX = /abc/g
REGEX.test('abc');
> true
REGEX.test('abc'));
> falser/loljs • u/BaloneyGeek • Mar 28 '16
When is not a number a number?
$: node
> typeof(NaN)
'number'
>r/loljs • u/SSPmrsomebody1 • May 23 '18
[]==[] and []===[] return false.
...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 • u/Takeoded • Apr 29 '17
big numbers are equal
>100000000000000000==99999999999999999
<truethe scary part, === doesn't even notice this
>100000000000000000===99999999999999999
<trueand if you try a string:
>100000000000000000=="99999999999999999"
<truebut at least, it notices that 1 is a string and the other a number:
>100000000000000000==="99999999999999999"
<falsefinally! some sanity
and in case you wonder, "use strict" makes no difference.
r/loljs • u/Silly-Freak • Oct 25 '19
async/await is new, why give it PHP-style coercion semantics?
r/loljs • u/MarkyC4A • Sep 02 '16
Adding an Object in an Object creates a key based on the variable name
jsfiddle.netr/loljs • u/Banane9 • Nov 17 '14
There second argument in substring and substr has different meanings
r/loljs • u/lukaseder • Jul 27 '14
Defeating infinity: parseInt(1 / 0, 19) == 18
r/loljs • u/getlaidanddie • May 27 '15
var a = Object.create(null)
typeof a // --> "object"
a instanceof Object // --> falser/loljs • u/monitorius1 • Mar 30 '18
This is from latest is-odd library debate
rextester.comr/loljs • u/[deleted] • Mar 27 '14
"0"==false is true, but if("0"){/* executes */}
r/loljs • u/sheldonkreger • Aug 03 '15
Node.JS "best practices" . . . or a long list of reasons why JS is poorly suited for async operations?
r/loljs • u/1114111 • Sep 20 '17
Array.from({lol: "js"}) returns empty array
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 • u/Takeoded • Jun 26 '22
Number properties are silently lost/discarded/undefined
r/loljs • u/[deleted] • 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
r/loljs • u/Takeoded • Jun 01 '21
NaN is iterable
> 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)
< []