DEV Community

Cover image for Is just typing the difference between Typescript and Javascript?
Luiz Calaça
Luiz Calaça

Posted on

Is just typing the difference between Typescript and Javascript?

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

Top comments (5)

Collapse
 
miketalbot profile image
Mike Talbot ⭐

Agreed, and I'd further argue that every other difference listed in the article is just about typing. I would say OOP is about: inheritance, encapsulation, polymorphism etc all of which are totally a fundamental part of Javascript in 2022.

Collapse
 
luizcalaca profile image
Luiz Calaça

Mike, thanks! That was the motive of my initial disclaimer that we could have more than one paradigm but maybe we cannot use all the concepts. I'm gonna add these contributions to the article.

Collapse
 
bradtaniguchi profile image
Brad

Javascript and Typescript have similar points in some cases, but the paradigm is different.

JavaScript is multi-paradigm. Since TS builds on-top of JS, it is also multi paradigm.

In both you can use, OOP, functional, procedural, declariative etc. Both also provide essentially the same level of "functionality", however, it's the syntax of how you get there that can be different. TS will force you to write type-safe code, when JS wont care.

However, the paradigm your leveraging to write your code will be the same. The paradigm is separate from the syntax and static/non-static types.

There is also the quirk that TS is as type-safe as you want it, from very strict to JS but with a bunch of any's floating around haha.

Collapse
 
luizcalaca profile image
Luiz Calaça

Great! Brad, thanks for contribuition.

Collapse
 
luizcalaca profile image
Luiz Calaça

Thanks for contributing, Nate! Excellent point. As I wrote above some language could have more than one paradigms but, as you say not so usable in practice, so the Javascript community focus on the functional paradigm and just a little in OOP.