"The languages you learn, the technologies you use, and the way you frame your thoughts will be a byproduct of your attempts to solve the problem."
Sean McClure
JavaScript
JavaScript was developed by Netscape in partnership with Sun Microsystems, and is now a Microsoft-patroned Open Source project. It has been an important part of web applications since the beginning, rendering web pages interactive and dynamic. Javascript has long been a client-side implementation, but there are also server-side implementations for JS engines.
TypeScript
TypeScript is a programming language developed and maintained by Microsoft. It is a JavaScript superset that compiles to plain JavaScript and has optional typing. Typescript provides optional static typing, classes, and interface, TypeScript was designed for the development of large applications.
TypeScript = JavaScript + Features
Which problem does TypeScript Solve?
A common question that can be asked, if we have JavaScript why TypeScript is developed? What is going to add in development?
At the beginning JavaScript was used as a client-side programming language, but while working with it developers figured out that this programming language can also be used as a server-side programming language!
At a certain moment and especially when developing large applications, it was clear that JavaScript code became complex and heavy and at this point JavaScript was not able to fulfill the requirement of Object Oriented Programming language. And this is what prevented JavaScript from succeeding at the enterprise level as a server side technology; TypeScript was developed to bridge this gap.
Features of TypeScript
● TypeScript code is transpiled (compiled and converted) into JavaScript code.
● Every JavaScript code can be converted into TypeScript code by changing the file extension from .js to .ts.
● TypeScript code is portable, can be run on any browser, and any operating system.
● TypeScript supports JavaScript code, such as using JavaScript libraries with TypeScript code.
● Static type annotation / Static Typing (optional).
● Supports interfaces, classes, ES6.
Features of JavaScript
● Cross-platform language used for both client side and server side.
● Freedom to do whatever you want with any object which makes it a flexible and powerful language
● Many powerful available libraries.
Key Differences
● JavaScript is a scripting language used to create interactive web pages and it’s also used on the server side whereas TypeScript is a superset of JavaScript.
● TypeScript code needs to be compiled.
● TypeScript uses interfaces and type to describe data used in the code while JavaScript does not have this feature.
Which one should I choose
As mentioned above in the section Which problem does TypeScript Solve we can say that for large size projects working with TypeScript will be a better choice, JavaScript is a good option for small size projects. By using TypeScript you’ll gain many advantages:
● You’ll get compilation errors on development time only, because the chance of getting errors at runtime are very small, and this is because TypeScript is a compiled language whereas JavaScript is an interpreted language.
● TypeScript is a strongly-typed language and also supports static typing, this guarantees that types are checked at compile time, which reduces the amount of errors and this is not available in JavaScript.
● TypeScript compiler can compile .ts files into ES3, ES4 and ES5 also.
The goal of this comparison is not to say that TypeScript is better than JavaScript or vice versa, it’s just to tell that programming languages are a tool for every developer and his task is to choose the right tool to solve real life problems!