This is part of why I don't like ternaries. Even if the person writing the ternary knows exactly what they're doing, someone else reading the ternary isn't sure that the writer actually meant what they wrote.
I think I'm just so used to them these days that it never occurs to me that they're unclear to anyone but junior devs. I like the brevity.
Having said that, I always read them with a subvocalised question intonation, so it always sounds like a "Really? Yes : No" in my head, which is maybe what has helped the pattern seem "obvious" to me.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think there's a bug in an early example. I suspect you intended
const x = y ? 1 : 0;
to beconst x === y ? 1 : 0;
No,
y
is the value I'm checking the value of, I'm then assigning1
or0
tox
based on whether it'strue
orfalse
respectively.Gotcha. I totally misread it. Sorry.
This is part of why I don't like ternaries. Even if the person writing the ternary knows exactly what they're doing, someone else reading the ternary isn't sure that the writer actually meant what they wrote.
I think I'm just so used to them these days that it never occurs to me that they're unclear to anyone but junior devs. I like the brevity.
Having said that, I always read them with a subvocalised question intonation, so it always sounds like a "Really? Yes : No" in my head, which is maybe what has helped the pattern seem "obvious" to me.