I’ve always learned that Javascript didn’t support private fields. You could use closures as a ‘language hack’ to keep information private but it is not at the same level of simplicity:
In the example above the privateVar field is not directly accessible.
As I switched to TypeScript a long time ago, I didn’t care too much and happily used the private keyword there.
Of course this was just a TypeScript hack and in the generated Javascript, the field was still accessible.
More recently I switched to a different syntax in TypeScript to specify private fields:
What I wasn’t aware of that this became the default way that private fields are specified in Javascript.
Cool!