Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
nummer312239yIf u are new to js like i was and did not get this then it can be written as customer && addNewCustomer(customer) -
@nummer31 I actually prefer this over the && for the sake of clarity. Except I'd get rid of the unnecessary curly braces ;)
-
I'd get rid of the inequality altogether. Both null and undefined are treated as false, so if you write
if (customer)
Then you have a general existence check without needing to specify all the kinds of falsy values it could be -
rivertam499y@ElectricCoffee yeah but then if the customer could be false, that's an invalid value. Obviously customer would never be false, but it's a bad habit to form. -
@rivertam that would then beg the question, if the customer is false, why then would you want to add it?
In any case if the contest makes sense, there isn't a reason not to do it -
nummer312239yThe code can be written in multiple ways but that would be most verbose way possible.
Related Rants

What only relying on JavaScript for HTML form input validation looks like
Found something true as 1 == 1
Me as a C# dev, new to JS
undefined
js
c#