TypeScript vs. JavaScript

Zachary Horvath

Zachary Horvath 2021-11-06 3 min read #softwareengineering

JavaScript, commonly shortened to JS, is a programming language that conforms to the ECMAScript specification. This specification has been updated yearly since 2015 and cements JS as a high-level, just-in-time compiled language. There are features such as dynamic typing, prototypes, and curly-bracket syntax.

JS is a core web technology, and powers most web page behavior (97% of client-side according to Wikipedia). JS is also capable of performing on the server with Node.js and on mobile with React Native, empowering developers to learn one programming language to create a multitude of full-stack applications. JavaScript is widely recognized as a leading programming language to learn for this reason. This popularity leads to more open source projects, more tutorials, more jobs, and plenty of resources to learn from. Powerful as it is, JavaScript lacks native type checking, which can often result in undetectable bugs and abnormal behavior in production applications. To address this issue, especially in enterprise projects, TypeScript was created.

TypeScript, created and maintained by Microsoft and often shortened to TS, is essentially JavaScript with syntax for types. Natively, TypeScript compels developers to explicitly define data types and provide additional descriptions to objects and functions within their code. TS also has a tighter integration with the code editor (VS Code specifically) that greatly improves the descriptions surrounding errors. This increases the developer's ability to identify bugs and other potential issues in code prior to it reaching production level.

TS is notably powerful in enterprise applications, where large code bases are often marred with difficult-to-find bugs and code errors. Typically, these errors are hard to uncover in a traditional JavaScript codebase. In a TypeScript project, however, bugs are uncovered earlier on in development, reducing or eliminating the potential for issues to appear in production. In addition to an improved development experience, this also results in less customer-facing bugs and an overall better application, be it web, mobile, or server.

Additional features of TypeScript include type annotations, compile-time type checking, type inference, type erasure, interfaces, enumerated types, generics, and more. As a superset of JavaScript, TS remains fully compatible. All JS code works seamlessly with TypeScript given proper type declarations. This allows JavaScript developers to seamlessly transition to TypeScript with minor code revisions. All other syntax remains intact and even .js files work in a TypeScript project without issue!

As far as which programming language is better, as a superset of JavaScript, TypeScript has distinct advantages in that it builds on top of JS to effectively improve the development experience, especially on large projects. The tighter integration with the code editor as well as added type declarations add to the overall appeal. Especially at a production enterprise level, TypeScript shines as the clear winner.

Back