JavaScript. By far one of the most famous programming languages for its applications in scripting, gamedev and most notably web apps 🌐. Then its brother, TypeScript. Famous for being statically typed. It adds more features to JavaScript. Which one is better? 🤔 I guess today we find out.
Disclaimer
What follows is going to be my opinion inferred from fact. This may or may not be true. Please read this article accordingly.
JavaScript
JavaScript has many features, scripting, web apps and is even supported in some game engines. To sum it up nicely:
- ✔ Dynamically typed (beginners don't mix up typing)
- ❌ No optional parameters
- ❌ No interfaces
- ✔ Some game engine support
- ✔ Compiled not transpiled
- ❌ No TS file imports
TypeScript
TypeScript has similar syntax to JavaScript but with a few features added.
- ❌ Statically typed
- ✔ Optional parameters
- ✔ Interfaces
- ❌ Transpiled
- ✔ Both TS and JS imports
- ✔ Most JS frameworks support TS
Based on all of this, and my experience using both languages. I would say that TypeScript is better than JavaScript. You may disagree however. If you do, please comment 💬! I would love to hear your opinions!
Top comments (22)
Currently at stage-3: MDN: Private class fields
@babel/plugin-proposal-private-met...
Other JavaScript practices: Managing the private data of ES6 classes
TypeScript adoption: ECMAScript Private Fields
Regarding new proposal: why to use
#
instead ofprivate
keyword for the private members? Or am I missing something here?FAQ:
Ok...
:slight_smile:
I think you mean 😊
Typescript is used in Unity, Phaser, Excalibur. I'm sure there are more, but the listing of Typescript not having Game Engine Support is inaccurate.
Ok but I thought Unity removed UnityScript?
forum.unity.com/threads/does-unity...
It appears it is deprecated but not removed yet, but that does not mean we should use UnityScript until it's gone, so it's a fair point. Aside from Unity, most JS game engines come with either their own typings or have 3rd party typings available. Assuming you have a decent IDE and a project setup, you should be able to use Typescript with any JS game engine (Though without the support, like you mentioned).
I like Typescript a lot.
As do I. I like the static typing.
and intelliscense, typescript provide in vscode
It does. 😅
From TypeScript is not JavaScript:
TypeScript is essentially a JavaScript superlinter that requires more information than ESLint.
One has to become competent in JavaScript one way or another - TypeScript or not. The official TypeScript documentation doesn't cover the JavaScript foundation that TypeScript is based on.
Some projects are using TypeScript to develop "typed JavaScript":
This is true but they are different enough that people can have a preference. Hence this article 😃.
There are a few mistakes. With Babel, you can import TypeScript directly from within JavaScript, though it needs a bit of setup. In JavaScript, all parameters are optional by default, because their types are obviously not enforced. JavaScript is only JiT-compiled, otherwise an interpreted language.
With Deno coming along, there will be a time when typescript gets executed the same way javascript does, as Deno has first-class support for typescript, which would at some point eliminate the Transpiled negative depending on the use case.
I will remove it when the time comes then!
Short & sweet article.
My only comment is while JS doesn't have optional parameters "natively", it can still be treated that way. It won't complain that you didn't provide a value for a parameter, and you can structure you code to see if a parameter is given or undefined.
Does that sway your opinion of it being better than TS? - probably not. Just sayin 😏
Well, technically JS is both compiled and interpreted. Read this answer for more details.
But isn't JS more compiled than interpreted (sorry if I'm wrong, I'm not the most experienced JS dev)