Skip to main content

Command Palette

Search for a command to run...

Learning TypeScript - Part 1

What is JavaScript and Why we need to use TypeScript?.

Updated
3 min readView as Markdown
Learning TypeScript - Part 1

Typescript, Typescript, Typescript... Everywhere I could see Typescript and even the in the quote like this below

Adapting Typescript one day, keeps the JavaScript problems away

Before we take a look on TypeScript, Let's have a glimpse of JavaScript now.

What is JavaScript?

JavaScript is a high-level, often just-in-time compiled language that conforms to the ECMAScript standard. It has dynamic typing, prototype-based object-orientation, and first-class functions. It is multi-paradigm, supporting event-driven, functional, and imperative programming styles. It has application programming interfaces (APIs) for working with text, dates, regular expressions, standard data structures, and the Document Object Model (DOM).

How JavaScript was used on early days?

JavaScript was invented to be a simple scripting language for the browsers. It was used to write small code snippets embedded in web page Early browsers executed JavaScript very slowly when there are more number of lines need to be executed. As time went, JavaScript became more popular as more number of developers used it to add more interactions with web page.

How the performance of JavaScript was improved?

Since web browsers suffered a lot in performance, the web browser developers started optimizing their JavaScript execution engines having dynamic compilation, adding more APIs etc. And JavaScript became popular even more when it was made to run in the backend servers using Node JS.

Some shortcomings of JavaScript

When the size, scope and complexity of programs written in JavaScript has grown exponentially, it is said that the ability of the JavaScript to express the relationships between different units of code has not grown. Problems like getting an input of different data type than expected, difficulty on finding basic logic and legitimate errors during the development time etc. makes difficult to manage complex JavaScript code base in large scale. To find a solution for these problems, after two years of internal development Microsoft introduced TypeScript on October 2012.

So what is TypeScript?

"TypeScript is JavaScript's runtime with a compile-time type checker" to find the basic logical, typographical errors during the development time. It has a strong type system which adds rules about how different kinds of values can be used in the program. We can define the data types of the variables, defining the skeleton of the objects using interfaces and custom data types.

Typescript preserves the runtime behaviour of the JavaScript. JavaScript will output "Infinity" when we try to divide a number by zero. As a principle Typescript never changes these kind of runtime behaviour by throwing errors like “Divide by zero error” instead it doesn’t change the underlying working of JavaScript, So we can migrate to TypeScript without any issues.

Typescript compiles the TypeScript code to plain JavaScript code without the types. At the end of the day we are going to execute the pure JavaScript code in our application. TypeScript doesn't provide any additional runtime libraries. JavaScript programs can use same JavaScript Internal / External libraries that we are already got used to.

Thanks for reading. We can see more about TypeScript in future!.