0
JavaScript (x, y)
Why : Var x = (y1, y2) is equal to y2 In JavaScript
16 Respuestas
+ 5
It is a bad practice, because of low readability
+ 5
I'd like to call in my specialist for bad practices, undefined behaviours and such, ~ swim ~ (if you don't mind, I'm being a pest ^^).
+ 5
What makes it a bad practice, then, if you know exactly how it works?
+ 4
a good use case is :
a && (b, c)
means :
if (a) {
b;
return c;
}
+ 3
Is that a similar behavior to C, where you can with your left hand crement some values while you're storing a value with the right one?
var n = (++x, --y, z);
+ 3
using this syntax in REACT is a pretty and simple thing ✊🏾 Schindlabua if u used react before u will understand 🤞🏼
+ 3
Oussama Messaoudi Seeing how you argue with Schindlabua, may I refer you to read this article, which is a programmer's heartfelt advice on why you shouldn't write "clean" code based on his real work experience.
https://www.sololearn.com/post/223948/?ref=app
https://code.sololearn.com/WKKkpq0efxai/?ref=app
+ 2
why using this syntax ?
what is the benefit ???
+ 2
HonFu It's bad practice because there's always a cleaner alternative.
var n = (++x, --y);
parses much much easier if you write it as
++x;
--y;
var n = y;
+ 2
Oussama Messaoudi that is pretty ugly :/
I mean, it's clever, but after a couple of hours of staring at code you don't really have the energy for "clever" code.
It takes 5 seconds to write it more readably, and it also takes 5 seconds to read the shorter code; BUT you have to read the code 100 times and only write it once, so just go for the if :P
+ 1
why ?
+ 1
why is that syntax correct ?
+ 1
The comma operator is a close cousin of the && and || operators. All three operators will return the last expression they evaluate
+ 1
It is not a good practice because the application or requirement of client (you) the practitioner will face an ambiguous problem or take more time to resolve the equation code and deliver the application
Please note that the requirement should be clear then only the client will get ouput what they are expecting
0
Oussama Messaoudi I think the comma is mostly there so we can do many assignments like
a = 1, b = 2, c = 3;