What is JavaScript? ๐ค
JavaScript is a dynamically typed interpreted programming language, It is used in client and server side programming . The beautiful dynamic websites you see is build using javascript. It is used in frontend(for bringing a dynamic nature to our website, it is generally used with HTML,CSS) and backend (express.js, node.js)for handling all the client side requests.
What is TypeScript?๐ค๐ค
It is a static typed compiled programming language, it can do everything as javascript, both the client side and server side programming. It is the superset of javascript, it has more features and is better than javascript. 'tsc' is the typescript compiler which converts the typescript code to javascript which is run by node.js.
JavaScript or TypeScript.๐คท๐คทโโ๏ธ
Type System
JavaScript: It is dynamically typed, meaning you don't have to specify variable types, and types can change at runtime.
TypeScript: It is statically typed, allowing you to declare types for variables and catch type-related errors at compile time.(pre-production). A study showed that TypeScript could successfully detect 15% of JavaScript bugs. You will some how escape the 'undefined' from the output.
// javascript
let name = "Julie";
// typescript
let name: string = "Julie";
Tooling
JavaScript: Lacks advanced development tooling for large projects, which can make it harder to maintain. Generally javascript is not used for making bigger projects.
TypeScript: Provides a rich set of tools, such as autocompletion, refactoring support, and type checking, enhancing developer productivity.
Object Orientation
JavaScript: It follows all the rules of object oriented programming but lacks in interfaces, access modifiers (public, private, protected).However, these concepts can be achieved through the use of closures.
TypeScript: It supports Object-Oriented Programming concepts like classes, encapsulation, inheritance, abstraction, and interfaces. It also supports generics, generics are another key feature of TypeScript that contribute to its strong typing system. Generics allow you to write reusable, type-safe code.
Conclusion
Generally typescript is used in making bigger projects as it saves so much time, by fixing the errors and bugs at the compile time without running it. But the syntax of the typescript may be overwhelming to people. And javascript is used for making small and medium projects, with its easy syntax.