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'}
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'}
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)
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())
Typescript has Interface, Javascript not?
interface Person {
firstName: string;
lastName: string;
}
let john: Person = {
firstName: 'Luiz',
lastName: 'Calaça'
}
Typescript has Enum, Javascript not?
enum State {
Progress = "In Progress",
Finished = "Finished",
NotCompleted = "Not completed "
}
//State.Progress
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);
}
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)
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.
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.
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.Great! Brad, thanks for contribuition.
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.