Is just typing the difference between Typescript and Javascript?

Luiz Calaça - Feb 13 '22 - - Dev Community

Hi, Devs!

So, the Typescript language came out and rapidly was being used around the Dev World. The important think is always use de correct tool to answer the problem, either Typescript or Javascript, or even other language.

To know important characteristics/concepts in programming we need to go back and read the literature about Computer Science and the essentials of languages.

A good example to learn is about transpiler, because the Typescript transpiler converts Typescript code to JavaScript.

And to answer the question of the title: Absolutely there are a lot of differences. And to get start, let's go to learn some concepts.


## const printJ = () => {return 'Javascript'}
Enter fullscreen mode Exit fullscreen mode

What is dynamic typing?

Dynamically-typed languages perform type checking at runtime.

What is functional programming?

That's a programming paradigm where programs are constructed by applying and composing functions.


## const printT = (): string => {return 'Typescript'}
Enter fullscreen mode Exit fullscreen mode

What is static typing?

Statically typed languages perform type checking at compile time.

What is oriented object programming (OOP)?

That's a programming paradigm where programs are modeled by applying objects (classes, interfaces, abstract class, inheritance)


programming paradigm

Typescript has classes, Javascript not?

class Person {
   private name: string = ''
   private age: number = 0

   constructor(name: string, age: number){
      this.name = name
      this.age = age
   }

   getName(): string { return this.name }

   getAge(): number { return this.age }
}

const teste = new Person('Calaça', 32)
console.log(teste.getName())

Enter fullscreen mode Exit fullscreen mode

Typescript has Interface, Javascript not?

interface Person {
    firstName: string;
    lastName: string;
}

let john: Person = {
    firstName: 'Luiz',
    lastName: 'Calaça'
}
Enter fullscreen mode Exit fullscreen mode

Typescript has Enum, Javascript not?

enum State {
    Progress = "In Progress",
    Finished = "Finished",
    NotCompleted = "Not completed "
}

//State.Progress
Enter fullscreen mode Exit fullscreen mode

Typescript has Generics, Javascript not?

export abstract class IGenericRepository<T> {
  abstract getAll(): Promise<T[]>;

  abstract get(id: string): Promise<T>;

  abstract create(item: T): Promise<T>;

  abstract update(id: string, item: T);
}
Enter fullscreen mode Exit fullscreen mode

And so on.. Javascript and Typescript has a similar points in some cases, but the paradigm is different.

Thats's a set of concise characteristics (classes, interface, generics, type, inheritance, polymorphism, encapsulations) that got the hype of Typescript, because seems like more clean, organized and good for a better code and also for its documentation maintenance through Microsoft.

Contacts
Email: luizcalaca@gmail.com
Instagram: https://www.instagram.com/luizcalaca
Linkedin: https://www.linkedin.com/in/luizcalaca/
Twitter: https://twitter.com/luizcalaca

. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player