Hacker News new | ask | show | jobs
by eiopa 3825 days ago
ES6 got this right too.

This design decision makes me die a little every time I have to do:

  def foo(x=None):
      if not x:
          x = []
      ...
1 comments

That will get you into trouble as well, please use:

    if x is None:
        x = []
... etc.
Or even "prettier":

  x = [] if x is None else x
I'm partial to:

x = x or []

Only works when x is truthy for all legal x values, excluding x=0.