subreddit stringclasses 7
values | author stringlengths 3 20 | id stringlengths 5 7 | content stringlengths 67 30.4k | score int64 0 140k |
|---|---|---|---|---|
loljs | kenman | dk3wwjg | <|soss|><|sot|>Should acronyms be spelled all caps or camel case? XMLHttpRequest: Why not both?<|eot|><|sost|><|eost|><|sor|>[deleted]<|eor|><|sor|>As is HTTP...<|eor|><|sor|>as is REQUEST<|eor|><|sor|>No? `Request` is literally the word _request_ -- it's not an acronym.<|eor|><|eoss|><|endoftext|> | 11 |
loljs | mort96 | dir5a82 | <|soss|><|sot|>Should acronyms be spelled all caps or camel case? XMLHttpRequest: Why not both?<|eot|><|sost|><|eost|><|sor|>I also haven't really ever seen anyone actually use it for XML, it's mostly used for JSON.<|eor|><|eoss|><|endoftext|> | 6 |
loljs | fact_hunt | 3odiun | <|sols|><|sot|>NodeJS: stripping comments can speed up your code<|eot|><|sol|>https://medium.com/@c2c/nodejs-a-quick-optimization-advice-7353b820c92e<|eol|><|eols|><|endoftext|> | 34 |
loljs | Vortico | cvwaios | <|sols|><|sot|>NodeJS: stripping comments can speed up your code<|eot|><|sol|>https://medium.com/@c2c/nodejs-a-quick-optimization-advice-7353b820c92e<|eol|><|sor|>Also switching to tab-indention or fewer-spaces indention would do it.<|eor|><|eols|><|endoftext|> | 6 |
loljs | TheShyro | 8n13p3 | <|sols|><|sot|>NPM stops working with proxies, returns "418 I'm a teapot"<|eot|><|sol|>https://github.com/npm/npm/issues/20791<|eol|><|eols|><|endoftext|> | 29 |
loljs | SpoliatorX | dztc8k7 | <|sols|><|sot|>NPM stops working with proxies, returns "418 I'm a teapot"<|eot|><|sol|>https://github.com/npm/npm/issues/20791<|eol|><|sor|>While that *is* a valid HTTP status code I feel like it's probably not correct for them to use it here<|eor|><|eols|><|endoftext|> | 9 |
loljs | CyberDiablo | d3jc46 | <|sols|><|sot|>Why ['1', '7', '11'].map(parseInt) returns [1, NaN, 3] in Javascript<|eot|><|sol|>https://medium.com/dailyjs/parseint-mystery-7c4368ef7b21<|eol|><|eols|><|endoftext|> | 24 |
loljs | WASDx | 3k89jb | <|sols|><|sot|>Doing a javascript online test, this was probably the hardest question.<|eot|><|sol|>http://i.imgur.com/aXNeZ76.png<|eol|><|eols|><|endoftext|> | 26 |
loljs | opatut | cuvt1j5 | <|sols|><|sot|>Doing a javascript online test, this was probably the hardest question.<|eot|><|sol|>http://i.imgur.com/aXNeZ76.png<|eol|><|sor|>Answer: [Hover for Spoiler](/s "C, D, E should not be left blank") <|eor|><|eols|><|endoftext|> | 5 |
loljs | hhalahh | 46fy4y | <|sols|><|sot|>reducing comment length (and presumably variable length) gives 50% speedup<|eot|><|sol|>https://top.fse.guru/nodejs-a-quick-optimization-advice-7353b820c92e<|eol|><|eols|><|endoftext|> | 25 |
loljs | hhalahh | d05f579 | <|sols|><|sot|>reducing comment length (and presumably variable length) gives 50% speedup<|eot|><|sol|>https://top.fse.guru/nodejs-a-quick-optimization-advice-7353b820c92e<|eol|><|sor|>There is a reason for the 600 char limit though.
It is not like it is a magic gain.
The 600 char limit exists to decide whether a function should be inlined or not. Inline expansion is when the compiler puts the whole function in your cpus instruction cache.
The downside of this is that it will take longer to find all other functions.
Do not minify huge code to try and fit it under the limit, do not make the limit larger than necessary; although the time to run that single function will go down, **the time to run all functions afterwards will go up.**
Instead of calling a function from another function 500000000 times maybe look for a way to refactor your code.
>
>[ As a rule of thumb, some inlining will improve speed at very minor cost of space, but excess inlining will hurt speed, due to inlined code consuming too much of the instruction cache, and also cost significant space.](https://en.wikipedia.org/wiki/Inline_expansion)<|eor|><|soopr|>>Do not minify huge code to try and fit it under the limit
\>implying I use JS more than once a year
you'd think they'd at least count AST nodes or something instead of text length<|eoopr|><|eols|><|endoftext|> | 9 |
loljs | esquilax | d060bjr | <|sols|><|sot|>reducing comment length (and presumably variable length) gives 50% speedup<|eot|><|sol|>https://top.fse.guru/nodejs-a-quick-optimization-advice-7353b820c92e<|eol|><|sor|>There is a reason for the 600 char limit though.
It is not like it is a magic gain.
The 600 char limit exists to decide whether a function should be inlined or not. Inline expansion is when the compiler puts the whole function in your cpus instruction cache.
The downside of this is that it will take longer to find all other functions.
Do not minify huge code to try and fit it under the limit, do not make the limit larger than necessary; although the time to run that single function will go down, **the time to run all functions afterwards will go up.**
Instead of calling a function from another function 500000000 times maybe look for a way to refactor your code.
>
>[ As a rule of thumb, some inlining will improve speed at very minor cost of space, but excess inlining will hurt speed, due to inlined code consuming too much of the instruction cache, and also cost significant space.](https://en.wikipedia.org/wiki/Inline_expansion)<|eor|><|soopr|>>Do not minify huge code to try and fit it under the limit
\>implying I use JS more than once a year
you'd think they'd at least count AST nodes or something instead of text length<|eoopr|><|sor|>You know the story of function naming in PHP being used to balance out a hash table with a shitty hash function, right?<|eor|><|soopr|>heard something similar to that but never read about it<|eoopr|><|sor|>http://i-programmer.info/news/98-languages/6758-the-reason-for-the-weird-php-function-names.html
lolci (laughing out loud, crying inside)<|eor|><|eols|><|endoftext|> | 7 |
loljs | esquilax | d05sl70 | <|sols|><|sot|>reducing comment length (and presumably variable length) gives 50% speedup<|eot|><|sol|>https://top.fse.guru/nodejs-a-quick-optimization-advice-7353b820c92e<|eol|><|sor|>There is a reason for the 600 char limit though.
It is not like it is a magic gain.
The 600 char limit exists to decide whether a function should be inlined or not. Inline expansion is when the compiler puts the whole function in your cpus instruction cache.
The downside of this is that it will take longer to find all other functions.
Do not minify huge code to try and fit it under the limit, do not make the limit larger than necessary; although the time to run that single function will go down, **the time to run all functions afterwards will go up.**
Instead of calling a function from another function 500000000 times maybe look for a way to refactor your code.
>
>[ As a rule of thumb, some inlining will improve speed at very minor cost of space, but excess inlining will hurt speed, due to inlined code consuming too much of the instruction cache, and also cost significant space.](https://en.wikipedia.org/wiki/Inline_expansion)<|eor|><|soopr|>>Do not minify huge code to try and fit it under the limit
\>implying I use JS more than once a year
you'd think they'd at least count AST nodes or something instead of text length<|eoopr|><|sor|>You know the story of function naming in PHP being used to balance out a hash table with a shitty hash function, right?<|eor|><|eols|><|endoftext|> | 6 |
loljs | esquilax | d0xcil7 | <|sols|><|sot|>reducing comment length (and presumably variable length) gives 50% speedup<|eot|><|sol|>https://top.fse.guru/nodejs-a-quick-optimization-advice-7353b820c92e<|eol|><|sor|>There is a reason for the 600 char limit though.
It is not like it is a magic gain.
The 600 char limit exists to decide whether a function should be inlined or not. Inline expansion is when the compiler puts the whole function in your cpus instruction cache.
The downside of this is that it will take longer to find all other functions.
Do not minify huge code to try and fit it under the limit, do not make the limit larger than necessary; although the time to run that single function will go down, **the time to run all functions afterwards will go up.**
Instead of calling a function from another function 500000000 times maybe look for a way to refactor your code.
>
>[ As a rule of thumb, some inlining will improve speed at very minor cost of space, but excess inlining will hurt speed, due to inlined code consuming too much of the instruction cache, and also cost significant space.](https://en.wikipedia.org/wiki/Inline_expansion)<|eor|><|soopr|>>Do not minify huge code to try and fit it under the limit
\>implying I use JS more than once a year
you'd think they'd at least count AST nodes or something instead of text length<|eoopr|><|sor|>You know the story of function naming in PHP being used to balance out a hash table with a shitty hash function, right?<|eor|><|sor|>strlen is not a hash function.<|eor|><|sor|>Well *I* know that...<|eor|><|eols|><|endoftext|> | 5 |
loljs | OdinCasino | n25c8n | <|soss|><|sot|>(new Date()).getYear() === 121<|eot|><|sost|><|eost|><|eoss|><|endoftext|> | 21 |
loljs | Earhacker | gwhcrto | <|soss|><|sot|>(new Date()).getYear() === 121<|eot|><|sost|><|eost|><|sor|>JavaScript, invented in 1995, isn't Y2K compliant.<|eor|><|eoss|><|endoftext|> | 11 |
loljs | jordan314 | gwhokub | <|soss|><|sot|>(new Date()).getYear() === 121<|eot|><|sost|><|eost|><|sor|>JavaScript, invented in 1995, isn't Y2K compliant.<|eor|><|sor|>They couldn't think 5 years ahead?<|eor|><|eoss|><|endoftext|> | 9 |
loljs | OdinCasino | gwi6r9m | <|soss|><|sot|>(new Date()).getYear() === 121<|eot|><|sost|><|eost|><|sor|>JavaScript, invented in 1995, isn't Y2K compliant.<|eor|><|sor|>They couldn't think 5 years ahead?<|eor|><|soopr|>This is when boomers where in their 30's writing stuff... of course they didnt think 5 years ahead.
i wonder what the origin of "where do you see yourself in 5 years" is...<|eoopr|><|eoss|><|endoftext|> | 8 |
loljs | Aphix | gwjl50s | <|soss|><|sot|>(new Date()).getYear() === 121<|eot|><|sost|><|eost|><|sor|>.getFullYear()<|eor|><|eoss|><|endoftext|> | 7 |
loljs | Aphix | gwjlcjf | <|soss|><|sot|>(new Date()).getYear() === 121<|eot|><|sost|><|eost|><|sor|>wtf happened 121 years ago?<|eor|><|sor|>1900, which was considered bt some to be a better start of the epoch than 1970<|eor|><|eoss|><|endoftext|> | 6 |
loljs | JayCroghan | gwieqny | <|soss|><|sot|>(new Date()).getYear() === 121<|eot|><|sost|><|eost|><|sor|>JavaScript, invented in 1995, isn't Y2K compliant.<|eor|><|sor|>They couldn't think 5 years ahead?<|eor|><|sor|>lol most software written in the 90s was thought to be temporary.
>Surely someone will do this better shorty, I just need this for the time being.<|eor|><|eoss|><|endoftext|> | 6 |
loljs | Krenair | gwj958s | <|soss|><|sot|>(new Date()).getYear() === 121<|eot|><|sost|><|eost|><|sor|>wtf happened 121 years ago?<|eor|><|sor|>nothing, it just isn't Y2K compliant. it used to be very common to give years relative to 1900. caused a whole lot of silliness around the turn of the century<|eor|><|eoss|><|endoftext|> | 5 |
loljs | ThisIsADogHello | 4p286n | <|sols|><|sot|>If the first argument to `setTimeout` is a string, it will be implicitly `eval`'ed [x-post /r/ProgrammerTIL]<|eot|><|sol|>https://www.reddit.com/r/ProgrammerTIL/comments/4oxr7b/javascript_if_the_first_argument_to_settimeout_is/<|eol|><|eols|><|endoftext|> | 24 |
loljs | sheldonkreger | 474sd6 | <|sols|><|sot|>The Node.js Event Loop is a Damn Mess<|eot|><|sol|>http://sheldonkreger.com/the-nodejs-event-loop-is-a-damn-mess.html<|eol|><|eols|><|endoftext|> | 19 |
loljs | loljs | 2elo78 | <|sols|><|sot|>Node.js leadership<|eot|><|sol|>http://i.imgur.com/AZJti8I.png<|eol|><|eols|><|endoftext|> | 20 |
loljs | Harkins | ckwpz4b | <|sols|><|sot|>Node.js leadership<|eot|><|sol|>http://i.imgur.com/AZJti8I.png<|eol|><|sor|>This is missing a tweet from @izs, which I think goes right above (and thus temporally after) @garybernhardts's "This toot makes me mad."
> @garybernhardt Sounds like you have feelings. You should seek a therapist, or a close friend. (Note that I am neither.)<|eor|><|eols|><|endoftext|> | 10 |
loljs | dry_hopped | ckws3c4 | <|sols|><|sot|>Node.js leadership<|eot|><|sol|>http://i.imgur.com/AZJti8I.png<|eol|><|sor|>What a waste of everybody's time an attention.<|eor|><|eols|><|endoftext|> | 9 |
loljs | kmark937 | ck9nbkb | <|sols|><|sot|>Node.js leadership<|eot|><|sol|>http://i.imgur.com/AZJti8I.png<|eol|><|sor|>>Thanks, blocked
8 tweets after "Sorry, our time is up."<|eor|><|eols|><|endoftext|> | 8 |
loljs | pcopley | cmm9sa1 | <|sols|><|sot|>Node.js leadership<|eot|><|sol|>http://i.imgur.com/AZJti8I.png<|eol|><|sor|>I know this is 3 months old, but I just felt the need to come here and state that @izs is a piece of shit.
Thank you for your time.<|eor|><|eols|><|endoftext|> | 5 |
loljs | Takeoded | npspu3 | <|soss|><|sot|>NaN is iterable<|eot|><|sost|>```
> 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)
< []
```<|eost|><|eoss|><|endoftext|> | 17 |
loljs | Apollidore | h07akex | <|soss|><|sot|>NaN is iterable<|eot|><|sost|>```
> 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)
< []
```<|eost|><|sor|>I've checked why, this is because Array.from(YYY) calls an internal JS function called GetMethod to get @@iterator ([https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration\_protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)) from YYY and GetMethod will throw an Error if YYY is null or undefined
Every other non-iterable YYY will be converted to an Object (so NaN becomes a Number), which is considered as an array-like object whose length is 0
By the way the title is wrong, NaN is not iterable as it doesn't have any @@iterator but the confusion is understandable!<|eor|><|eoss|><|endoftext|> | 8 |
loljs | g00glen00b | 3clv62 | <|soss|><|sot|>Who was first, the function or the object?<|eot|><|sost|> Object instanceof Function; // true
Function instanceof Object; // true
Looks like a chicken/egg problem to me, which one was first, the `Object` or the `Function`?<|eost|><|eoss|><|endoftext|> | 18 |
loljs | krznpsk | cswruoy | <|soss|><|sot|>Who was first, the function or the object?<|eot|><|sost|> Object instanceof Function; // true
Function instanceof Object; // true
Looks like a chicken/egg problem to me, which one was first, the `Object` or the `Function`?<|eost|><|sor|>Both the chicken and the egg share a common ancestor<|eor|><|eoss|><|endoftext|> | 9 |
loljs | Takeoded | vl77n1 | <|sols|><|sot|>Number properties are silently lost/discarded/undefined<|eot|><|sol|>https://i.redd.it/efcf4li0iz791.png<|eol|><|eols|><|endoftext|> | 17 |
loljs | Takeoded | idtdvno | <|sols|><|sot|>Number properties are silently lost/discarded/undefined<|eot|><|sol|>https://i.redd.it/efcf4li0iz791.png<|eol|><|soopr|>luckily things are better with "use strict":
```
(function(){
"use strict";
let i=5;
i.foo="wut";
})();
```
gives
>Uncaught TypeError: Cannot create property 'foo' on number '5'<|eoopr|><|eols|><|endoftext|> | 8 |
loljs | Ragnagord | 4fpnkr | <|sols|><|sot|>Why does [5,6,8,7][1,2] = 8 in Javascript?<|eot|><|sol|>http://stackoverflow.com/questions/7421013/why-does-5-6-8-71-2-8-in-javascript<|eol|><|eols|><|endoftext|> | 15 |
loljs | z500 | d2ax4t0 | <|sols|><|sot|>Why does [5,6,8,7][1,2] = 8 in Javascript?<|eot|><|sol|>http://stackoverflow.com/questions/7421013/why-does-5-6-8-71-2-8-in-javascript<|eol|><|sor|>The comma operator is my favorite dirty C trick. It's so obscure, but C-style languages still bring the comma operator with them. Ever initialize more than one variable in the initializer of a for loop without questioning it? You were using the comma operator.<|eor|><|eols|><|endoftext|> | 8 |
loljs | Laugarhraun | 2m9rp6 | <|sols|><|sot|>Node.js production release ships with no longer supported (by anyone) version of V8<|eot|><|sol|>https://code.google.com/p/v8/issues/detail?id=3692#c6<|eol|><|eols|><|endoftext|> | 16 |
loljs | MazeChaZer | 7g37g2 | <|soss|><|sot|>JSON.stringify(new Set([1, 2, 3])) === '{}'<|eot|><|sost|><|eost|><|eoss|><|endoftext|> | 14 |
loljs | MazeChaZer | dqgd9a3 | <|soss|><|sot|>JSON.stringify(new Set([1, 2, 3])) === '{}'<|eot|><|sost|><|eost|><|sor|>Yes? The argument is not stored as exposed properties on the object. `JSON.stringify`only handles exposed properties.
This'll work just fine:
JSON.stringify(Array.from(new Set([1, 2, 3])))
Although, it changes the contents form an object to an array.
Not a loljs. Just /r/shittyprogramming<|eor|><|soopr|>Your statement that `JSON.stringify` only handles exposed properties is not correct. Any object in JavaScript can implement a method called `toJSON` to define a custom serialization strategy. This works for the `Date` class: `JSON.stringify(new Date()) === '"2017-11-28T14:04:16.326Z"'`.
I know that it works when you use `Array.from`, but why doesn't the `Set` class provide a useful `toJSON` implementation by itself?<|eoopr|><|eoss|><|endoftext|> | 17 |
loljs | suspiciously_calm | dqh6t0d | <|soss|><|sot|>JSON.stringify(new Set([1, 2, 3])) === '{}'<|eot|><|sost|><|eost|><|sor|>Yes? The argument is not stored as exposed properties on the object. `JSON.stringify`only handles exposed properties.
This'll work just fine:
JSON.stringify(Array.from(new Set([1, 2, 3])))
Although, it changes the contents form an object to an array.
Not a loljs. Just /r/shittyprogramming<|eor|><|sor|>Yes, simply accepting everything under the sun and silently serializing it as an empty object instead of raising an error is very much a loljs.
The fact that this loosey typey approach is burned into the language and can't easily be unfucked is an even bigger loljs.<|eor|><|eoss|><|endoftext|> | 17 |
loljs | suspiciously_calm | dqh8fam | <|soss|><|sot|>JSON.stringify(new Set([1, 2, 3])) === '{}'<|eot|><|sost|><|eost|><|sor|>Yes? The argument is not stored as exposed properties on the object. `JSON.stringify`only handles exposed properties.
This'll work just fine:
JSON.stringify(Array.from(new Set([1, 2, 3])))
Although, it changes the contents form an object to an array.
Not a loljs. Just /r/shittyprogramming<|eor|><|sor|>Yes, simply accepting everything under the sun and silently serializing it as an empty object instead of raising an error is very much a loljs.
The fact that this loosey typey approach is burned into the language and can't easily be unfucked is an even bigger loljs.<|eor|><|sor|>I couldn't disagree more. :)
You cannot expect any object - native or otherwise - to be serializable.
The interface of `Set` is utilized incorrectly in the example in the topic. The language does exactly what it should and as one should expect. There's no quirkiness going on. It's completely reliable. It's not a loljs.<|eor|><|sor|>> You cannot expect any object - native or otherwise - to be serializable.
So you should get an error when you try.<|eor|><|eoss|><|endoftext|> | 17 |
loljs | kafoso | dqh1nlc | <|soss|><|sot|>JSON.stringify(new Set([1, 2, 3])) === '{}'<|eot|><|sost|><|eost|><|sor|>Yes? The argument is not stored as exposed properties on the object. `JSON.stringify`only handles exposed properties.
This'll work just fine:
JSON.stringify(Array.from(new Set([1, 2, 3])))
Although, it changes the contents form an object to an array.
Not a loljs. Just /r/shittyprogramming<|eor|><|soopr|>Your statement that `JSON.stringify` only handles exposed properties is not correct. Any object in JavaScript can implement a method called `toJSON` to define a custom serialization strategy. This works for the `Date` class: `JSON.stringify(new Date()) === '"2017-11-28T14:04:16.326Z"'`.
I know that it works when you use `Array.from`, but why doesn't the `Set` class provide a useful `toJSON` implementation by itself?<|eoopr|><|sor|>`toJSON` is exposure. Same with `toString`.
I do agree it would probably have made sense to have a `Set.toJSON` function available. But you cannot assume it exists on any object, really.<|eor|><|eoss|><|endoftext|> | 7 |
loljs | kafoso | dqhx99i | <|soss|><|sot|>JSON.stringify(new Set([1, 2, 3])) === '{}'<|eot|><|sost|><|eost|><|sor|>Yes? The argument is not stored as exposed properties on the object. `JSON.stringify`only handles exposed properties.
This'll work just fine:
JSON.stringify(Array.from(new Set([1, 2, 3])))
Although, it changes the contents form an object to an array.
Not a loljs. Just /r/shittyprogramming<|eor|><|sor|>Yes, simply accepting everything under the sun and silently serializing it as an empty object instead of raising an error is very much a loljs.
The fact that this loosey typey approach is burned into the language and can't easily be unfucked is an even bigger loljs.<|eor|><|sor|>I couldn't disagree more. :)
You cannot expect any object - native or otherwise - to be serializable.
The interface of `Set` is utilized incorrectly in the example in the topic. The language does exactly what it should and as one should expect. There's no quirkiness going on. It's completely reliable. It's not a loljs.<|eor|><|sor|>> You cannot expect any object - native or otherwise - to be serializable.
That could well be the title of another /r/loljs post, with your comment as the end of the link.
<|eor|><|sor|>It's true. Circular patterns/recursion will cause `JSON.stringify` to throw an error. And no object, which hasn't specifically disabled extension/injection, is protected from outside intervention. Consider this example:
var error = new Error("foo");
error.self = error;
JSON.stringify(error);
This'll result in the error:
Uncaught TypeError: Converting circular structure to JSON
Also, /r/loljs is about illogical, quirky, counter-intuitive, or even funny things in the Javascript programming language. A plentiful palette. It's not about how some programmer incorrectly utilizes an object's interface.<|eor|><|eoss|><|endoftext|> | 7 |
loljs | Nwallins | jfjrbo | <|sols|><|sot|>Just wait till you see what it costs to use functional syntax sugar instead of for loops everywhere!<|eot|><|sol|>https://www.reddit.com/r/programming/comments/jf6by8/using_constlet_instead_of_var_can_make_javascript/g9ijb1z/<|eol|><|eols|><|endoftext|> | 14 |
loljs | hurenkind5 | 4itedk | <|sols|><|sot|>What could go wrong?<|eot|><|sol|>https://reaktor.com/blog/node-js-satellite-means-anyone-can-space-programmer/<|eol|><|eols|><|endoftext|> | 14 |
loljs | Michal_Perlakowski | 6c6b5p | <|sols|><|sot|>Spread operator magically turns functions into 'not functions'<|eot|><|sol|>http://stackoverflow.com/q/44071673/3853934<|eol|><|eols|><|endoftext|> | 13 |
loljs | mort96 | dhsbiyx | <|sols|><|sot|>Spread operator magically turns functions into 'not functions'<|eot|><|sol|>http://stackoverflow.com/q/44071673/3853934<|eol|><|sor|>The problem here seems to be that the double function returns a number, and he's trying to apply the spread operator to the result of calling the function. The spread operator obviously doesn't work on numbers.
The loljs is that the error message OP got was weird and misleading, though others are reporting to get more sane errors.<|eor|><|eols|><|endoftext|> | 5 |
loljs | MazeChaZer | 573r25 | <|sols|><|sot|>npm can't into sensible lock file handling and --save by default, now Facebook rewrites the whole thing from scratch<|eot|><|sol|>https://code.facebook.com/posts/1840075619545360/yarn-a-new-package-manager-for-javascript/<|eol|><|eols|><|endoftext|> | 13 |
loljs | mort96 | d8pfhil | <|sols|><|sot|>npm can't into sensible lock file handling and --save by default, now Facebook rewrites the whole thing from scratch<|eot|><|sol|>https://code.facebook.com/posts/1840075619545360/yarn-a-new-package-manager-for-javascript/<|eol|><|sor|>So why does Facebook have to check in node_modules into the repo? It sounds like they're trying to solve a problem that is ultimately because they're using npm not as it's intended.<|eor|><|sor|>From the article:
> Initially, following the prescribed best practices, we only checked in package.json and asked engineers to manually run npm install. This worked well enough for engineers, but broke down in our continuous integration environments, which need to be sandboxed and cut off from the internet for security and reliability reasons.<|eor|><|eols|><|endoftext|> | 5 |
loljs | getlaidanddie | 37gder | <|soss|><|sot|>var a = Object.create(null)<|eot|><|sost|> typeof a // --> "object"
a instanceof Object // --> false<|eost|><|eoss|><|endoftext|> | 13 |
loljs | 00Davo | ctwemd5 | <|soss|><|sot|>var a = Object.create(null)<|eot|><|sost|> typeof a // --> "object"
a instanceof Object // --> false<|eost|><|sor|>This is totally unsurprising behaviour? `Object.create(null)` produces a new object which doesn't extend from anything, whereas `{}` produces a new object that extends from `Object`. That's the *point* of `Object.create(null)`.<|eor|><|eoss|><|endoftext|> | 5 |
loljs | xiata | 75rolf | <|sols|><|sot|>Chrome: Array.prototype.sort() uses an unstable sort algorithm unlike Edge, Firefox, or Safari<|eot|><|sol|>https://jsfiddle.net/L2r2dLek/3/<|eol|><|eols|><|endoftext|> | 12 |
loljs | Silly-Freak | dmv0u9 | <|sols|><|sot|>async/await is new, why give it PHP-style coercion semantics?<|eot|><|sol|>https://i.redd.it/tchk2xoqonu31.jpg<|eol|><|eols|><|endoftext|> | 12 |
loljs | throbbaway | ctyrur | <|soss|><|sot|>I've been trying to become acquainted with "modern" JS today...<|eot|><|sost|>Did you know these three functions do 3 distinct things?
​
let changeName1 = newName => (
{
name: newName
}
)
let changeName2 = newName => {
{
name: newName
}
}
let changeName3 = newName => { name: newName }
​
Can you tell how?<|eost|><|eoss|><|endoftext|> | 10 |
loljs | 1kGarand | 22qodc | <|soss|><|sot|>++[[]][+[]]+[+[]] === "10"<|eot|><|sost|>from a reddit comment. I wish I could find it again for proper credit.<|eost|><|eoss|><|endoftext|> | 13 |
loljs | Takeoded | qn8fhu | <|soss|><|sot|>ele.children.length=0 , ele.firstChild = Text node<|eot|><|sost|>running this on reddit,
ele=document.getElementsByTagName("span")[0];
ele.children; // empty HTMLCollection[]
ele.children.length; // 0
it evidently has no children, ok.. quoting [mdn on firstChild](https://developer.mozilla.org/en-US/docs/Web/API/Node/firstChild):
> The Node.firstChild read-only property returns the node's first child in the tree, or null if the node has no children.
ok, so ele.firstChild should be null then,
ele.firstChild; // Text node
ele.firstChild.toString(); // '[object Text]'
ele.firstChild.nodeValue; // 'Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts'
wtf js? it has no children, except firstChild, but firsChild doesn't count..<|eost|><|eoss|><|endoftext|> | 10 |
loljs | SoInsightful | hjioyzx | <|soss|><|sot|>ele.children.length=0 , ele.firstChild = Text node<|eot|><|sost|>running this on reddit,
ele=document.getElementsByTagName("span")[0];
ele.children; // empty HTMLCollection[]
ele.children.length; // 0
it evidently has no children, ok.. quoting [mdn on firstChild](https://developer.mozilla.org/en-US/docs/Web/API/Node/firstChild):
> The Node.firstChild read-only property returns the node's first child in the tree, or null if the node has no children.
ok, so ele.firstChild should be null then,
ele.firstChild; // Text node
ele.firstChild.toString(); // '[object Text]'
ele.firstChild.nodeValue; // 'Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts'
wtf js? it has no children, except firstChild, but firsChild doesn't count..<|eost|><|sor|>There's no good logic behind it, but `.firstChild` refers to `.childNodes`, which includes text and comment nodes, not `.children`, which for some reason only includes elements.<|eor|><|eoss|><|endoftext|> | 5 |
loljs | SSPmrsomebody1 | 8lhzyk | <|soss|><|sot|>[]==[] and []===[] return false.<|eot|><|sost|>...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".<|eost|><|eoss|><|endoftext|> | 10 |
loljs | Nulagrithom | dzgam7q | <|soss|><|sot|>[]==[] and []===[] return false.<|eot|><|sost|>...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".<|eost|><|sor|>Does js compare arrays by checking each element? It might be that you are allocating two empty arrays and comparing their pointers. As for the iteration thing I have no clue.<|eor|><|sor|>That's exactly what's happening. References aren't the same, therefore the arrays aren't the same.
Pretty sure this would happen in a lot of languages.<|eor|><|eoss|><|endoftext|> | 19 |
loljs | Earhacker | dzh1gzt | <|soss|><|sot|>[]==[] and []===[] return false.<|eot|><|sost|>...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".<|eost|><|sor|>Does js compare arrays by checking each element? It might be that you are allocating two empty arrays and comparing their pointers. As for the iteration thing I have no clue.<|eor|><|sor|>That's exactly what's happening. References aren't the same, therefore the arrays aren't the same.
Pretty sure this would happen in a lot of languages.<|eor|><|sor|>Ruby:
irb(main):001:0> [] == []
=> true
irb(main):002:0> [] === []
=> true
`==` checks equality of value, `===` has a [really weird behaviour](https://stackoverflow.com/questions/3422223/vs-in-ruby) in Ruby.
Python:
>>> [] == []
True
>>> [] is []
False
`==` checks equality, `is` checks identity, i.e. the two objects are the same reference in memory
JavaScript:
> [] == []
false
> [] === []
false
`==` checks for equality of value, `===` checks for equality of value and type. But unlike Ruby and Python, arrays are not a type in JavaScript:
Ruby:
irb(main):002:0> [].class
=> Array
Python:
>>> type([])
<class 'list'>
JavaScript:
> typeof []
'object'
...they're just objects. So in JavaScript you're comparing two empty *objects* with no defined equality method. And since the two objects occupy different addresses in memory, they are not equal.
This behaviour, with bare objects, is identical to how Ruby and Python behave:
Ruby:
irb(main):003:0> Object.new == Object.new
=> false
irb(main):004:0> Object.new === Object.new
=> false
Python:
>>> object() == object()
False
>>> object() is object()
False<|eor|><|eoss|><|endoftext|> | 13 |
loljs | Pstuc002 | dzftjna | <|soss|><|sot|>[]==[] and []===[] return false.<|eot|><|sost|>...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".<|eost|><|sor|>Does js compare arrays by checking each element? It might be that you are allocating two empty arrays and comparing their pointers. As for the iteration thing I have no clue.<|eor|><|eoss|><|endoftext|> | 9 |
loljs | Kazumz | dzhpn91 | <|soss|><|sot|>[]==[] and []===[] return false.<|eot|><|sost|>...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".<|eost|><|sor|>This seems to be entirely valid because they are different references. Feel free to correct me.<|eor|><|eoss|><|endoftext|> | 5 |
loljs | Nulagrithom | dzha1gu | <|soss|><|sot|>[]==[] and []===[] return false.<|eot|><|sost|>...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".<|eost|><|sor|>Does js compare arrays by checking each element? It might be that you are allocating two empty arrays and comparing their pointers. As for the iteration thing I have no clue.<|eor|><|sor|>That's exactly what's happening. References aren't the same, therefore the arrays aren't the same.
Pretty sure this would happen in a lot of languages.<|eor|><|sor|>Ruby:
irb(main):001:0> [] == []
=> true
irb(main):002:0> [] === []
=> true
`==` checks equality of value, `===` has a [really weird behaviour](https://stackoverflow.com/questions/3422223/vs-in-ruby) in Ruby.
Python:
>>> [] == []
True
>>> [] is []
False
`==` checks equality, `is` checks identity, i.e. the two objects are the same reference in memory
JavaScript:
> [] == []
false
> [] === []
false
`==` checks for equality of value, `===` checks for equality of value and type. But unlike Ruby and Python, arrays are not a type in JavaScript:
Ruby:
irb(main):002:0> [].class
=> Array
Python:
>>> type([])
<class 'list'>
JavaScript:
> typeof []
'object'
...they're just objects. So in JavaScript you're comparing two empty *objects* with no defined equality method. And since the two objects occupy different addresses in memory, they are not equal.
This behaviour, with bare objects, is identical to how Ruby and Python behave:
Ruby:
irb(main):003:0> Object.new == Object.new
=> false
irb(main):004:0> Object.new === Object.new
=> false
Python:
>>> object() == object()
False
>>> object() is object()
False<|eor|><|sor|>Interesting. What happens when you do the JS equivalent of `[{}] === [{}]` in Ruby and Python?<|eor|><|eoss|><|endoftext|> | 5 |
loljs | Earhacker | dzhoo3p | <|soss|><|sot|>[]==[] and []===[] return false.<|eot|><|sost|>...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".<|eost|><|sor|>Does js compare arrays by checking each element? It might be that you are allocating two empty arrays and comparing their pointers. As for the iteration thing I have no clue.<|eor|><|sor|>That's exactly what's happening. References aren't the same, therefore the arrays aren't the same.
Pretty sure this would happen in a lot of languages.<|eor|><|sor|>Ruby:
irb(main):001:0> [] == []
=> true
irb(main):002:0> [] === []
=> true
`==` checks equality of value, `===` has a [really weird behaviour](https://stackoverflow.com/questions/3422223/vs-in-ruby) in Ruby.
Python:
>>> [] == []
True
>>> [] is []
False
`==` checks equality, `is` checks identity, i.e. the two objects are the same reference in memory
JavaScript:
> [] == []
false
> [] === []
false
`==` checks for equality of value, `===` checks for equality of value and type. But unlike Ruby and Python, arrays are not a type in JavaScript:
Ruby:
irb(main):002:0> [].class
=> Array
Python:
>>> type([])
<class 'list'>
JavaScript:
> typeof []
'object'
...they're just objects. So in JavaScript you're comparing two empty *objects* with no defined equality method. And since the two objects occupy different addresses in memory, they are not equal.
This behaviour, with bare objects, is identical to how Ruby and Python behave:
Ruby:
irb(main):003:0> Object.new == Object.new
=> false
irb(main):004:0> Object.new === Object.new
=> false
Python:
>>> object() == object()
False
>>> object() is object()
False<|eor|><|sor|>Interesting. What happens when you do the JS equivalent of `[{}] === [{}]` in Ruby and Python?<|eor|><|sor|>False across the board.
Ruby:
irb(main):005:0> [Object.new] == [Object.new]
=> false
irb(main):006:0> [Object.new] === [Object.new]
=> false
Python:
>>> [object()] == [object()]
False
>>> [object()] is [object()]
False
JavaScript:
> [{}] == [{}]
false
> [{}] === [{}]
false
Ruby and Python both see an array containing *the same* empty object as equivalent, but JavaScript doesn't.
Ruby:
irb(main):007:0> empty = Object.new
=> #<Object:0x007f8309a3b090>
irb(main):008:0> [empty] == [empty]
=> true
irb(main):009:0> [empty] === [empty]
=> true
Python:
>>> empty = object()
>>> [empty] == [empty]
True
>>> [empty] is [empty]
False
\(the objects are the same, but the lists are not\)
JavaScript:
> empty = {}
{}
> empty == empty
true
> [empty] == [empty]
false
> [empty] === [empty]
false
\(the variable `empty` is the same as itself, but we already know that JS arrays which contain equal objects are not themselves equal, because the arrays are just objects and not really arrays\)<|eor|><|eoss|><|endoftext|> | 5 |
loljs | lhgaghl | 1xoenm | <|sols|><|sot|>JSt world problems<|eot|><|sol|>http://fifod.com/why-you-should-always-use-and-other-bad-practices/<|eol|><|eols|><|endoftext|> | 9 |
loljs | 1114111 | 71859r | <|soss|><|sot|>Array.from({lol: "js"}) returns empty array<|eot|><|sost|>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](http://www.ecma-international.org/ecma-262/6.0/#sec-iterator-interface) iterators to define `Symbol.iterator` [like Python does for `__iter__`](https://docs.python.org/3/library/stdtypes.html#typeiter). 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.<|eost|><|eoss|><|endoftext|> | 9 |
loljs | samdroid_ | 697ctq | <|sols|><|sot|>Arithmetic with JavaScript Arrays<|eot|><|sol|>https://learntemail.sam.today/blog/arithmetic-with-javascript-arrays/<|eol|><|eols|><|endoftext|> | 10 |
loljs | BillOReillyYUPokeMe | 4ipm6b | <|soss|><|sot|>~!!"0"[+'hello']+'2.99';<|eot|><|sost|>> "-12.99"
What the fuck?<|eost|><|eoss|><|endoftext|> | 11 |
loljs | eof | 1pln77 | <|soss|><|sot|>javascript sorts arrays lexographically by default<|eot|><|sost|> >a = [1.2, 8.8, 11.4]
[1.2, 8.8, 11.4]
>a.sort()
[1.2, 11.4, 8.8]
<|eost|><|eoss|><|endoftext|> | 9 |
loljs | Takeoded | eebe2l | <|soss|><|sot|>decodeURIComponent()<|eot|><|sost|> > decodeURIComponent()
< "undefined"
yup, the decoded version of absolutely nothing is string literal `"undefined"`
for comparison, here's what PHP does:
$ php -r 'var_dump(urldecode());'
PHP Warning: urldecode() expects exactly 1 parameter, 0 given in Command line code on line 1
NULL<|eost|><|eoss|><|endoftext|> | 8 |
loljs | the_alias_of_andrea | fbt17m4 | <|soss|><|sot|>decodeURIComponent()<|eot|><|sost|> > decodeURIComponent()
< "undefined"
yup, the decoded version of absolutely nothing is string literal `"undefined"`
for comparison, here's what PHP does:
$ php -r 'var_dump(urldecode());'
PHP Warning: urldecode() expects exactly 1 parameter, 0 given in Command line code on line 1
NULL<|eost|><|soopr|>decodeURI() and encodeURI() and encodeURIComponent() is also affected.
but what should have happened? i'm a bit conflicted, arguably an empty string is an accurate url-encoded representation of nothing, so returning an empty string would have been appropriate. but doing something like
TypeError: decodeURI requires 1 argument, but only 0 were passed
would also make sense (example from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/More_arguments_needed )
but returning String("undefined") is definitely not the right thing to do.<|eoopr|><|sor|>Isn't this standard behaviour in JavaScript: functions accepting strings will convert implicitly to string, and undefined's implicit string conversion is `"undefined"`?<|eor|><|eoss|><|endoftext|> | 5 |
loljs | jonnyburger | 5pxikb | <|soss|><|sot|>let r = /abc/g; console.log(r.test('abc'), r.test('abc')); // true false<|eot|><|sost|> const REGEX = /abc/g
REGEX.test('abc');
> true
REGEX.test('abc'));
> false
<|eost|><|eoss|><|endoftext|> | 8 |
loljs | z500 | dcum15j | <|soss|><|sot|>let r = /abc/g; console.log(r.test('abc'), r.test('abc')); // true false<|eot|><|sost|> const REGEX = /abc/g
REGEX.test('abc');
> true
REGEX.test('abc'));
> false
<|eost|><|sor|>The first call to `test` advances `REGEX.lastIndex` to 3, the length of the matched string. The second call to `test` attempts to match the regex to the part remaining after the last match, which is "".
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex<|eor|><|eoss|><|endoftext|> | 13 |
loljs | phvcky | dcvnk7s | <|soss|><|sot|>let r = /abc/g; console.log(r.test('abc'), r.test('abc')); // true false<|eot|><|sost|> const REGEX = /abc/g
REGEX.test('abc');
> true
REGEX.test('abc'));
> false
<|eost|><|sor|>As /u/z500 correctly pointed out, this is intended behavior. Remove the global flag or reset `r.lastIndex = 0`.
Shitpost.<|eor|><|eoss|><|endoftext|> | 13 |
loljs | sheldonkreger | 3fnshq | <|sols|><|sot|>Node.JS "best practices" . . . or a long list of reasons why JS is poorly suited for async operations?<|eot|><|sol|>http://justbuildsomething.com/node-js-best-practices/<|eol|><|eols|><|endoftext|> | 8 |
loljs | BowserKoopa | ctrcbba | <|sols|><|sot|>Node.JS "best practices" . . . or a long list of reasons why JS is poorly suited for async operations?<|eot|><|sol|>http://justbuildsomething.com/node-js-best-practices/<|eol|><|sor|>Can be replaced with
> 1. Don't write in JavaScript<|eor|><|eols|><|endoftext|> | 10 |
loljs | Banane9 | cw7lgwm | <|sols|><|sot|>Node.JS "best practices" . . . or a long list of reasons why JS is poorly suited for async operations?<|eot|><|sol|>http://justbuildsomething.com/node-js-best-practices/<|eol|><|sor|>> When this happens the server would effectively be inaccessible for 30 minutes as that module is loaded. If this happens at peak hours several users would be unable to get any access to your server and requests will queue up.
Well, someone isn't expecting a lot of traffic...<|eor|><|eols|><|endoftext|> | 6 |
loljs | monitorius1 | 88dqxh | <|sols|><|sot|>This is from latest is-odd library debate<|eot|><|sol|>http://rextester.com/EYLHR12670<|eol|><|eols|><|endoftext|> | 6 |
loljs | Vortico | dwjwgft | <|sols|><|sot|>This is from latest is-odd library debate<|eot|><|sol|>http://rextester.com/EYLHR12670<|eol|><|sor|>This isn't realy loljs material because it is well-known that the 'number' JS type is an IEEE 754 double.<|eor|><|eols|><|endoftext|> | 11 |
loljs | loljs | 2aztvm | <|sols|><|sot|>JavaScript Jeopardy<|eot|><|sol|>https://twitter.com/jsjeopardy<|eol|><|eols|><|endoftext|> | 7 |
loljs | Takeoded | 68bfi0 | <|soss|><|sot|>big numbers are equal<|eot|><|sost|> >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.<|eost|><|eoss|><|endoftext|> | 4 |
loljs | arilotter | dgx6i1f | <|soss|><|sot|>big numbers are equal<|eot|><|sost|> >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.<|eost|><|sor|>Isn't this just an IEEE floating point problem that would happen in any language without a data type large enough to store the number?
Of course, ideally it would throw a warning if you made a number that can't be well represented or something, but you can hardly fault JS for floating point problems like this <|eor|><|eoss|><|endoftext|> | 20 |
loljs | Drainedsoul | dgx93gs | <|soss|><|sot|>big numbers are equal<|eot|><|sost|> >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.<|eost|><|sor|>Not a quirk of Javascript, but a quirk of the fact that you can't represent arbitrarily large numbers with floating point.<|eor|><|sor|>And JavaScript doesn't have integers which kind of brings it back to being a quirk of JavaScript. <|eor|><|eoss|><|endoftext|> | 20 |
loljs | ConcernedInScythe | dgzr7x0 | <|soss|><|sot|>big numbers are equal<|eot|><|sost|> >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.<|eost|><|sor|>Isn't this just an IEEE floating point problem that would happen in any language without a data type large enough to store the number?
Of course, ideally it would throw a warning if you made a number that can't be well represented or something, but you can hardly fault JS for floating point problems like this <|eor|><|sor|>You can absolutely blame JS for deciding that using doubles as the only numerical type was a good idea.<|eor|><|eoss|><|endoftext|> | 18 |
loljs | Vortico | dgx9vby | <|soss|><|sot|>big numbers are equal<|eot|><|sost|> >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.<|eost|><|sor|>Not a quirk of Javascript, but a quirk of the fact that you can't represent arbitrarily large numbers with floating point.<|eor|><|sor|>And JavaScript doesn't have integers which kind of brings it back to being a quirk of JavaScript. <|eor|><|sor|>Okay, sure, but then the title should be "Javascript uses double precision floats for all number types" instead of this, but everyone knows that already.<|eor|><|eoss|><|endoftext|> | 9 |
loljs | Vortico | dgx9xry | <|soss|><|sot|>big numbers are equal<|eot|><|sost|> >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.<|eost|><|sor|>Isn't this just an IEEE floating point problem that would happen in any language without a data type large enough to store the number?
Of course, ideally it would throw a warning if you made a number that can't be well represented or something, but you can hardly fault JS for floating point problems like this <|eor|><|soopr|>at the very least, i blame it for not throwing a parsing error in strict mode<|eoopr|><|sor|>No, because typing things like 1267650600228229401496703205376 should be perfectly valid since it can be represented exactly as a float.<|eor|><|eoss|><|endoftext|> | 8 |
loljs | Takeoded | dgx6ojd | <|soss|><|sot|>big numbers are equal<|eot|><|sost|> >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.<|eost|><|sor|>Isn't this just an IEEE floating point problem that would happen in any language without a data type large enough to store the number?
Of course, ideally it would throw a warning if you made a number that can't be well represented or something, but you can hardly fault JS for floating point problems like this <|eor|><|soopr|>at the very least, i blame it for not throwing a parsing error in strict mode<|eoopr|><|eoss|><|endoftext|> | 7 |
loljs | Vortico | dgx6q8l | <|soss|><|sot|>big numbers are equal<|eot|><|sost|> >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.<|eost|><|sor|>Not a quirk of Javascript, but a quirk of the fact that you can't represent arbitrarily large numbers with floating point.<|eor|><|eoss|><|endoftext|> | 6 |
loljs | MarkyC4A | 50usqc | <|sols|><|sot|>Adding an Object in an Object creates a key based on the variable name<|eot|><|sol|>https://jsfiddle.net/ame8g6kv/1/<|eol|><|eols|><|endoftext|> | 5 |
loljs | amirmikhak | d77iybx | <|sols|><|sot|>Adding an Object in an Object creates a key based on the variable name<|eot|><|sol|>https://jsfiddle.net/ame8g6kv/1/<|eol|><|sor|>I'm honestly not sure what you think should happen here... I believe that this is a result of ES6 object shorthand syntax. Without a `:` after each key, the key for that entry becomes the value, as a string. For example, `{foo}` is the same as `{foo: foo}`. If foo were a variable with value `"bar"`, the object would be `{foo: "bar"}` in both cases.<|eor|><|eols|><|endoftext|> | 7 |
loljs | lukaseder | 2bugrg | <|sols|><|sot|>Defeating infinity: parseInt(1 / 0, 19) == 18<|eot|><|sol|>http://www.ctmmc.net/defeating-infinity<|eol|><|eols|><|endoftext|> | 5 |
loljs | phoborsh | eoaxb9 | <|sols|><|sot|>Does this nightmare of a language always execute things in the wrong order?<|eot|><|sol|>https://i.redd.it/1z1ctphv8ma41.jpg<|eol|><|eols|><|endoftext|> | 4 |
loljs | ipe369 | feb18zk | <|sols|><|sot|>Does this nightmare of a language always execute things in the wrong order?<|eot|><|sol|>https://i.redd.it/1z1ctphv8ma41.jpg<|eol|><|sor|>Does the function have async calls? 'cause that's just a language feature, not just js being dumb
Maybe the problem is you just don't know how to program in the language<|eor|><|eols|><|endoftext|> | 11 |
loljs | drumskirun | fecgz5s | <|sols|><|sot|>Does this nightmare of a language always execute things in the wrong order?<|eot|><|sol|>https://i.redd.it/1z1ctphv8ma41.jpg<|eol|><|sor|>First, console.out is not a function, console.log is. If you're this new to the language then you have some reading up to do on the Event Loop.
https://stackoverflow.com/q/49563818/6567214
Secondly, the behavior of console.log is dependant on the runtime, it's *not* a standardized part of the language.
https://stackoverflow.com/q/23392111/6567214<|eor|><|eols|><|endoftext|> | 8 |
loljs | Takeoded | 6mqoh9 | <|sols|><|sot|>What the... JavaScript? - Kyle Simpsons<|eot|><|sol|>https://www.youtube.com/watch?v=2pL28CcEijU<|eol|><|eols|><|endoftext|> | 4 |
loljs | sheldonkreger | 3imwgu | <|sols|><|sot|>Simply trying to figure out the type of a variable returned from an API call. I guess it's really hard.<|eot|><|sol|>http://stackoverflow.com/questions/7390426/better-way-to-get-type-of-a-javascript-variable<|eol|><|eols|><|endoftext|> | 3 |
loljs | Banane9 | 2mlr23 | <|sols|><|sot|>There second argument in substring and substr has different meanings<|eot|><|sol|>http://stackoverflow.com/questions/3745515/what-is-the-difference-between-substr-and-substring<|eol|><|eols|><|endoftext|> | 4 |
loljs | nalldom | 1hqs08 | <|sols|><|sot|>So I was debugging my validation since 4 hours...<|eot|><|sol|>http://stackoverflow.com/questions/894696/why-is-the-javascript-regexp-test-method-behaving-as-a-toggle<|eol|><|eols|><|endoftext|> | 3 |
loljs | lukaseder | 2d4t2u | <|soss|><|sot|>Hold your horses! ['10','10','10','10'].map(parseInt) yields [10, NaN, 2, 3]<|eot|><|sost|><|eost|><|eoss|><|endoftext|> | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.