8

Me as a C# dev, new to JS

Comments
  • 0
    If u are new to js like i was and did not get this then it can be written as customer && addNewCustomer(customer)
  • 1
    @nummer31 I actually prefer this over the && for the sake of clarity. Except I'd get rid of the unnecessary curly braces ;)
  • 0
    This is fine but it might be better to use != null here.
  • 1
    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
  • 0
    @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.
  • 0
    @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
  • 0
    The code can be written in multiple ways but that would be most verbose way possible.
Add Comment