JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)
What are the differences between javascript and typescript
Below are the list of differences between javascript and typescript,
| feature | typescript | javascript |
|---|---|---|
| Language paradigm | Object oriented programming language | Multi-paradigm language |
| Typing support | Supports static typing | Dynamic typing |
| Modules | Supported | Not supported |
| Interface | It has interfaces concept | Doesn't support interfaces |
| Optional parameters | Functions support optional parameters | No support of optional parameters for functions |
Practical Code Example
typescript
// JavaScript (Dynamic, runtime checking):
function calculate(price, tax) {
return price + tax; // If passed strings, accidentally concatenates!
}
// TypeScript (Static compile-time checking):
interface Order {
price: number;
tax: number;
}
function calculateStrict(order: Order): number {
return order.price + order.tax; // Compile error if invalid types passed
}