What is the difference between JavaScript and TypeScript?

Hi. I used JavaScript often and I have not tried using TypeScript. But I have a question.

What is the difference between JavaScript and TypeScript?

Please answer.

Thanks!
Pummarin :smile:

Hey @pummarinbest!
I have found some links to answer your question.

Hope this helps you,
Thanks and Happy Coding

1 Like

Lanuages have type systems: the logic that gives meaning to the various parts of the language. “This variable is a number”, “this variable is a boolean”, “this function accepts an argument that is a string and returns an array of strings”, etc.

The less strict those rules are, the more space there is for certain kinds of bugs (for example, in JS it is very easy to accidentally coerce one type of value to another).

The more strict the rules are, the closer those bugs become to impossible. But the trade-off is increased complexity (the language may be harder to use) and decreased flexibility (with that example, you may want the ability to easily coerce types).

So that is weak vs. strong typing. Languages like JavaScript and C are weakly typed. Languages like Python and C# are strongly typed.

The second thing with types is that there are basically two approaches to analyzing the types in a program:

  • static typing, where the source code is checked before it’s compiled to try to make sure the program is correct before it can be ran. So it’s written with types, and then converted to the actual end result if the type checker says it’s ok
  • dynamic typing, which often doesn’t have a compile step and where the code is type checked when it runs.

Languages like JavaScript and Python are dynamically typed. Languages like Typescript and Rust are statically typed.


So Typescript is a language, a statically typed version of JavaScript. You write the code in Typescript, the Typescript compiler checks the code to try to figure out if your program is correct, then it produces JavaScript that can run in a browser.

It is particularly helpful in larger applications, as it tends to make it much easier to have confidence in the code and avoid bugs.

The more complex the type system, generally the more the programmer needs to specify what the types of things are in the code, but the easier it is for the compiler to figure out if the code is logically correct (and from that, if it’s going to work). Typescript requires many things to be manually typed, though it can infer (guess) primitive types like numbers and strings.

Note all the above is a generalisation: there are lots of different approaches to type systems, different definitions of what is strong/weak typing, and different combinations of static/dynamic typing.

2 Likes