js
js copied to clipboard
[discussing] can ternary operators be used instead of if/else?
In a reused form component for both the record creation and the record modification, is it acceptable to use ternary operators instead of if/else like this?
this.formAction === 'edit' && this.recordValue ?
this.recordForm.setValue(this.recordValue) :
this.recordForm.reset();
It's a clear-cut case. With code-formatting of new-line and indent, it's quite readable. And in the foreseeable future, for each condition of the formAction, the business logic is unlikely to be changed.
What I'm asking is that, does this case prove confusing or not.
And what's more, since it's not an assignment, is it acceptable?
yes u can
Yes
@lalan-kumar-alt @SiyonaL Thanks