Live data from Hacker News

Safe Assignment

nalanj.dev

11–15 of 15 posts

Re: Safe Assignment

#13
This would make certain things more convenient, but wouldn't be very versatile and would feel terrible in terms of overall language semantics

Try expressions (mentioned in other comments) seem significantly better, but still feel like they're trying to tack on something that fits awkwardly into the original language design (though that's kind of the history of JavaScript)

Anyway, I'd use those all the time if they landed

Re: Safe Assignment

#15

The real safe assignment that I want to see is for optional chaining to be valid in LHS of assignments: foo?.bar = 42; This would not perform the assignment if an optionally chained value was nullish. It downlevels to foo == null ? undefined : foo.bar = 42; Given that the assignment is a SyntaxError now, this should be possible.

Would it evaluate the RHS? It feels like it shouldn’t, but somehow that seems weird too.
Post reply on HN