<aside> 👉 Feel free to check out the video if you missed lecture.

</aside>

Typescript | Frontend Lecture 11

<aside> 👉 Please download this before the lecture and follow along!

</aside>

N/A

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/51acf81c-923c-4ee7-8e88-a157c8af0b9a/wdblogogradient_1.png

Introduction

REPL.it link:

Basics

Typescript is a static type object-oriented programming language maintained by the Microsoft. It can be seen as a superset of Javascript. With the help of Typescript Compiler(TSC), we can convert typescript code to javascript and then it would be made understandable for the browser / node.

So, why do we need typescript if we can directly write in javascript? There are scenarios where javascript may not function that well.

As a result, typescript is gaining its popularity nowadays. It's crucial to understand typescript in a deeper level.

Syntax

Type

The biggest difference between JS and TS is the addition of static type checking.

function greeter(person) {
    return "Hello, " + person;
}

This is a normal javascript function. Let's see how should we rewrite it in typescript.

function greeter(person: string) {
    return "Hello, " + person;
}

If we try to put a different type as the person parameter, for example greeter([1,2,3]), we will get: