TypeScript · Junior · Question 41 of 75
How does private in TypeScript differ from #field in JavaScript?
- ✓Correct answer:
privateis only a compiler check,#fieldis privacy at runtime - 2No difference:
#fieldis just compiled into theprivatemodifier - 3
#fieldworks only in TypeScript and isn't supported by JS engines
Explanation
After compilation, a private field is an ordinary property that can be read via obj['field']. #field private fields are supported by the JS engine and can't be accessed from outside the class at all. The public, protected and private modifiers are TypeScript tools.