I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
I think nesting ternaries makes things more difficult to change later without scratching your head. The linked article says it simplifies the conventional if
At this point the if and the ternary are nearly identical, with the exception that the if statement blocks can contain anything they like without breaking the layout. Imagine if instead of returning a simple value they were all returning a long string or a calculation? I mean, you can say that these sorts of things should be factored into their own functions, but that's true of both techniques.
There is a very unfortunate drawback of using a function for "if" or ternary... both branches are always evaluated and that often means dereferencing null or undefined...
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 nesting ternaries makes things more difficult to change later without scratching your head. The linked article says it simplifies the conventional
if
but it doesn't go all the way:
At this point the
if
and the ternary are nearly identical, with the exception that theif
statement blocks can contain anything they like without breaking the layout. Imagine if instead of returning a simple value they were all returning a long string or a calculation? I mean, you can say that these sorts of things should be factored into their own functions, but that's true of both techniques.There is a very unfortunate drawback of using a function for "if" or ternary... both branches are always evaluated and that often means dereferencing null or undefined...