News for hackers. Stuff that matters.
Re:Safe Assignment by nuxi on Friday September 13, 2024 @02:21PM (#41533734)
You can avoid the SyntaxError by abusing boolean expressions a bit:

  > obj = {}
  {}
  > obj != null && (obj.bar = 42)
  42
  > obj
  { bar: 42 }
Not as pretty as your LHS case, but it works.
Re:Safe Assignment by Wingy on Friday September 13, 2024 @02:49PM (#41533971)
With the length of that you might as well do:

    if (obj) obj.bar = 42