Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
One more reason to dislike JS. But seriously, how? Does it have something to do with the spaces inbetween?
-
@virus Holy shit, that's nice. Especially the second answer(below the accepted one) is pretty crazy too:
var aοΎ = 1;
var a = 2;
var οΎ a = 3;
if(aοΎ ==1 && a== 2 &&οΎ a==3) {
console.log("Why hello there!")
}
(yes, this works...) -
@RAZERZ The trick here is that these are 3 different variables with invisible korean symbols or something, so JS interprets them differently but humans can't see that.
This would work in other languages too(like the greek question mark stuff) but nobody would really use that(at least that's my hope). -
I'm trying to force myself to learn js again and again but my brain resisted.. Things just doesn't work as I expected
-
@Zerocchi this is JS.
expecting it to make sense is the first rookie mistake, along with believing it has any actual syntax and not just style conventions -
@Midnigh-shcode yeah I just don't know how to face it solely because of that reasons, knowing every other languages make much more sense than js. I don't have a choice either, until WebAssembly become de facto standard. Probably transpilers is the only choice.
-
fyzrn27597yThe answers on SO don't really show JS's flaws IMO, most of them are pure trickery like the one using visually undistinguishable korean characters for variable names.
When I first heard that question, I was really excited to learn another JS quirk, I expected the answer to be messing with JS's coercion. Needless to say I'm disappointed, except for that answer which involves toString/valueOf. -
just because js allows you to make weak comparisons doesn't mean you should use it. it could be used as an exception, a "hackish" solution, but it's still a bad practice. every single linter for js code marks this as an error by default. just use strict comparison "===" and you won't have a problem.
-
nhll717yThis is why you always want to use === instead of == in JS, no exceptions. It's not true that JS makes no sense or has no syntax. For historic reasons, it obviously has more quirks and weird behaviors than most other languages. But I'd argue that if you don't learn stuff like this during your first steps in JS, you should be looking for a different teacher or learning resource instead of bashing the language.
Then again, it's pretty much impossible to know which of a language's basics you *should* be learning early, unless you already know these basics. Thus making it hard to judge the quality of your teacher/resource when starting out.
The thing with the Korean symbols implicates a programmer who's actively looking to create code that seems to be behaving in a weird way, even though it actually isn't. It doesn't apply to real world situations and I'm sure similar stuff is possible in other languages as well. -
52cal4987yThis question is testing your knowledge of type coercion and comparison operators (i.e. == v.s. ===) which is something every JS dev should know (junior included).
When you think you know enough Javascript to get a job, then this comes along Can (a ==1 && a== 2 && a==3)could evaluate to true, and the answer is freaking "yes" ππ.
rant