Typescript is the better Javascript
Tags: webdev, javascript, typescript
Published: 2021-04-17 09:41:35

---
title: Typescript is the better Javascript
published: true
description: Typescript is the better Javascript
tags: webdevelopment, javascript, typescript
cover_image: https://images.unsplash.com/photo-1498050108023-c5249f4df085?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1652&q=80
---

# Introduction
Hello there!
Javascript is THE language of the web and one or maybe the most used language in the world of programming. You can do everything with it, from building a simple portfolio website till build a complete SaaS product.

When i started learning Javascript i was hooked! I loved the language because its so versatile but over the time i realized that versatility has its price. And only Typescript can pay it!

# Static vs. dynamically typed languages
Javascript is a dynamically typed language that means that you dont specify a type for variables or functions. Javascript takes care of that. The type can change **AFTER** compile time (at the runtime).

This means you never know for sure if you assign a number to a variable if this variable really holds a number during the lifetime of the program. This can lead to really awkward errors.

For example this is valid Javascript Code:


```
2 + "2" = "22"
``` 


Seems weird if you ask me.

Typescript on the other hand is a static typed language where you define the type at compile time while you are coding. This means you get immediate feedback from your IDE when you try to assign a string to an integer variable for example. This reduces error and unwanted behavior to almost zero!

The second argument for static typed languages are that the programmer can read the code better and understand it more quickly. You can see which method returns which type, which parameter is which type.

# Typescript
But what is Typescript?
 [Typescript](https://www.typescriptlang.org/) is a superset of Javascript and was developed by Microsoft. Valid Javascript code is always valid Typescript code. And with Typescript you got many new features added to Javascript. Here are some examples:

### Types
The beauty of Typescript. You can give your variables, methods etc. types!


```
let myName: string = "Dany";
let myAge: number = 27;

public getPersonAge(): string {
    return this.myName;
}
``` 

You also can see that we can give our variables, methods etc. an access modifier like public or private to decide which is available only inside a class or also outside.

And even in Typescript you can give a variable a dynamic type if you really need to. In Typescript there is the "any" type.

### Object Oriented Programming
Sure in Javascript you also can code object oriented but in Typescript ist much, much easier! You can access modifiers like mentioned above, you get classes and interfaces and much more.

I really enjoy coding object oriented and its easy and fun in Typescript because you get things like mentioned above, Inheritance and such things out of the box!

# Conclusion
In my opinion Typescript is the better Javascript. You get a lot of cool, helpful features on top and no disadvantages at all.

As most things in life it depends on the person. Some of you may like and enjoy the freedom of Javascript and dont want to bound to typed and such things. And thats okay. But for me and may others out there Typescript really helps to organize the code better and enjoy to code more object oriented which is much easier with Typescript.

Stay connected to me and my content on [Twitter](https://twitter.com/danytulumidis).

I love to improve myself every single day even if its just a tiny bit!

Stay save and healthy guys!

And as always: develop yourself!