InterviewHubPRO
Section Overview
Q257

Question 257 of 521

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

49%
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,

featuretypescriptjavascript
Language paradigmObject oriented programming languageMulti-paradigm language
Typing supportSupports static typingDynamic typing
ModulesSupportedNot supported
InterfaceIt has interfaces conceptDoesn't support interfaces
Optional parametersFunctions support optional parametersNo 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
}