by 0xcoffee · 5y ago · 0 comments
_ = !isDefined(user) && throw new Error("User must be defined.");
_ = !isString(user.firstName) && throw new Error("User's first name must be a string");
But I while it is concise, I can also understand why people prefer regular if statements.Doesn't seem to be valid JS, can't remember where I got it from
_ = isDefined(user) || throw new Error("user must be defined")
This reads way more natural for me. "A user is defined OR throw an error"...I've also seen this in Perl (`do_something() || die()`) and shell scripts (`grep -q || die "not found"`).
[0] https://babeljs.io/docs/en/babel-plugin-proposal-throw-expre...
assert(isDefined(user),”User must be defined”) // throws if Falsy
{isLoading && <Loading />}