DanielM DanielM - 1 year ago 88
TypeScript Question

Why assignments don't return undefined?

As you may know, JavaScript returns

for assignments, e.g.
var a = 0;
. However, TypeScript is not consistent with that fact, and seems to return the assigned value (
) – yet I could not find any information about this online.

As an example, see this code snippet in the TypeScript playground.

I would like to learn the reasons behind this decision, and to hear opinions about it.

Answer Source

Your code snippet contains return (l = 2), not return (var l = 2), the former will return 2 in JavaScript, TypeScript, or indeed C or Java.