TypeScript VS JavaScript for Cocos Creator
With the cocos creator game development tool, two languages are supported for the development of games. The engine is built on top of cocos2d-X that uses C++ for the development of games but cocos creator itself supports Javascript and typeScript for game development. I generally prefer to use TypeScript in my projects so I will try to make you understand why that is my choice.
A brief distinction on the two languages (Javascript vs TypeScript)
Fellows, there is nothing complicated about the two languages in the discussion today if you understand that TypeScript is a superset of JavaScript. Think of TypeScript like JavaScript's older brother. The two languages in more ways are similar than different. Now there are differences between the two just like there are differences between brothers even if they are twins right? both languages are now using the ES6 in their latest variation but let's talk about it from the point of cocos creator.
- TypeScript can be strongly typed and that has a number of benefits. Strongly typed languages allow you to explicitly mention the type of variables that you want to use. you could for example want to use a number or a string. You can work with strongly typed variables with this and I find it useful coming from a C++ background.
- Error messages are easier to understand in my view because the interpreter or console 👀 understands the strongly typed TypeScript. JavaScript is loosely typed so debugging JavaScript, even for web developers can be a bit messy.
- The Cocos Creator generated .TS file is easier and less intimidating for newcomers to the engine than the JavaScript one. There is a lot of code in the .JS. Now, the code does the same thing and when you read it through, you will see that it is the same functions working but still, TypeScript is easier on the eyes. TypeScript is easier for newcomers.
- For people that do not know TypeScript. You can write JavaScript code in TypeScript files and it will be just as valid. You cannot write Typescript code in a JavaScript file but you can write JavaScript in a Typescript file. So if you are a JavaScript developer, fear not ! ! !
- For those that want to do game development even in other engines like Unity or Unreal. C# and C++ syntax will be closer to TypeScript than vanilla JavaScript. You might want to get used to TypeScript if you want to know a lot more about game engines.