Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[discussing] can ternary operators be used instead of if/else? #27

Open
KingMario opened this issue Oct 21, 2017 · 4 comments
Open

[discussing] can ternary operators be used instead of if/else? #27

KingMario opened this issue Oct 21, 2017 · 4 comments

Comments

@KingMario
Copy link

KingMario commented Oct 21, 2017

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.

@KingMario
Copy link
Author

KingMario commented Oct 21, 2017

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?

@lalan-kumar-alt
Copy link

yes u can

@SiyonaL
Copy link

SiyonaL commented Sep 19, 2022

Yes

@KingMario
Copy link
Author

@lalan-kumar-alt @SiyonaL Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants