I have an es6 model that I want to do some basic validation on before it is posted to an endpoint. I wrote a simple isValid() method on the class which I want to return true or false, not truthy, falsey. Since && will return last check which was truthy, I shortcut the function by appending && true to the end of my validation check.
export default class foo {
constructor (data = {}) {
this._id = data.id
this._name = data.name
}
isValid () {
return this._id && this._name && true
}
}
What I want to know is: Is this an appropriate way to return a true value in this context? Is there a better way to do this sort of validation in JS? I realize there are other ways to return a boolean doing 'if' statements, but I wanted this to be fairly concise and thought this might be a valid shortcut...