Live data from Hacker News

JavaScript Is Weird

jsisweird.com

141–150 of 383 posts

Re: JavaScript Is Weird

#141

Earlier quoted context omitted.

They don’t. They just use “console.log”, you see it because you opened the console. It’s not like they know you’re there and then write a message.

Devtools can actually be detected to a certain extent - https://github.com/sindresorhus/devtools-detect

> Doesn't work if DevTools is undocked and will show false positive if you toggle any kind of sidebar.

This annoys me every time because I use Tree Style Tab, and a website tries to detect DevTools. See Samy Kamkar's website [0].

[0]: https://samy.pl/

Re: JavaScript Is Weird

#142
post #19

0.2 + 0.1 === 0.3 That's not really a JS problem, that's a floating point problem. Plenty of languages will have the same issue. +!![] "" - - "" (null - 0) + "0" Calling these things weird is fair enough but I can't help thinking this is code you'd never actually write outside of the context of a "Look how weird JS is!" post. It's like picking examples from the Annual Obfuscated C Contest to show how hard it is to un…

Yup, garbage in garbage out. I'm not a huge fan of JS, but this sort of criticism is absurd.

I rather have the language say "Error, this is garbage!" than silently output garbage.

Re: JavaScript Is Weird

#143
post #134

Earlier quoted context omitted.

Yeah, a lot of these have nothing to do with JS. I have no idea what the site is trying to accomplish. I mean: !!!true In what language does that (or its equivalent) not evaluate to false?

In Go: https://play.golang.org/p/G8jOKtIj4AY

Can anyone explain this to me?

Re: JavaScript Is Weird

#144

Earlier quoted context omitted.

> [1, 2, 3] + [4, 5, 6] // -> "1,2,34,5,6" > What would you expect instead? If I let my first instinct speak: [1,2,3,4,5,6] And then if I think a little more, then maybe: [5,7,9] //with obvious caveats In no way do I expect what GP actually provided.

I understand where you are coming from. But the addition operator simply does not have any special handling of arrays. The specification [1] clearly defines what it should be used for: "The addition operator either performs string concatenation or numeric addition." As JavaScript is weakly typed, it is the programmer's responsibility to use proper value types with these operators. That limitation (or advantage?) is a…

well I guess the question is then not just what would you expect instead but at what familiarity with the language should one be asking people what they expect of it?

If you ask experts it is because you want to get an actual correct answer, but if you ask neophytes it is because you want to get an answer that might be obvious even if not correct.

Re: JavaScript Is Weird

#145

I have limited knowledge in web development and its history, but why is javascript a first class language in web dev when all I heard is "javascript bad"? Web assembly seems like a much better choice in hindsight where you can choose different language to compile down to wasm.

Webassembly is too recent. It needs to catch on. The momentum behind Javascript/Node is huge beyond comprehension. The engineering that has been poured into the JIT is also quite something. Just scrapping all of this and starting again with Wasm is not going to get traction from anyone.

Can you explain “Javascript/Node”? I thought Node.js was a JS interpreter but not the interpreter used in the major web browsers. Rather, that Node is an interpreter that’s used to run Js in (typically) headless (server) environments, allowing both sides to be written in JS. Is that accurate?

Re: JavaScript Is Weird

#146
Judging by the title, it sounded like the biggest discovery of 2021... by someone waking after a long coma. It was discovered in 2012: https://www.destroyallsoftware.com/talks/wat

I really enjoyed the questions... and even though I am working in TypeScript, I got only 9/25. Precisely because I avoid f---ed up parts of JS, except for trivia games (https://dorey.github.io/JavaScript-Equality-Table/unified/, http://www.jsfuck.com/).

Some parts of code need not to be understood. They need to be blocked by types, tests, and linters (https://p.migdal.pl/2020/03/02/types-tests-typescript.html).

Re: JavaScript Is Weird

#147
post #134

Earlier quoted context omitted.

In Go: https://play.golang.org/p/G8jOKtIj4AY

Can anyone explain this to me?

Looks like the `true` and `false` _bindings_ in Go are mutable and can be re-assigned. The same thing was possible in Python 2, IIRC:

    False, True = True, False # Have fun debugging!

Re: JavaScript Is Weird

#149

Earlier quoted context omitted.

They don’t. They just use “console.log”, you see it because you opened the console. It’s not like they know you’re there and then write a message.

Devtools can actually be detected to a certain extent - https://github.com/sindresorhus/devtools-detect

Seems like this guy is just using a width a height difference to detect this. Also some ‘window.FireBug’ property, that doesn’t turn up much currently in chrome or ff console on Ubuntu

Re: JavaScript Is Weird

#150
post #134

Earlier quoted context omitted.

Yeah, a lot of these have nothing to do with JS. I have no idea what the site is trying to accomplish. I mean: !!!true In what language does that (or its equivalent) not evaluate to false?

In Go: https://play.golang.org/p/G8jOKtIj4AY

One might want to add that it does work when you use a variable however. https://play.golang.org/p/6UfNFWm_-JR
Post reply on HN