What are the main differences between TypeScript and JavaScript?
Answer
TypeScript vs JavaScript key differences: (1) Static Typing — TypeScript has optional static types; JavaScript is dynamically typed. Types in TS are checked at compile time, preventing type-related bugs before they reach production. (2) Compilation — TypeScript must be compiled to JavaScript before it can run; JavaScript runs directly in the browser/Node. (3) Type Annotations — TS allows you to annotate variables, function parameters, and return types explicitly. (4) Advanced OOP features — TS adds interfaces, access modifiers (public/private/protected), abstract classes, and decorators. (5) Better IDE support — TypeScript enables richer autocomplete, refactoring, and error detection in editors. (6) Backwards compatibility — TypeScript can target any JavaScript version (ES5, ES6, ESNext). All JavaScript code is valid TypeScript, making migration incremental.