
Q. What is TypeScript? Why should we use it?
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript which runs on any browser or JavaScript engine.
TypeScript offers support for the latest JavaScript features and also has some additional features like static typing, object oriented programming and automatic assignment of constructor.
Q. What are Types in TypeScript?
The type represents the type of the value we are using in our programs. TypeScript supports simplest units of data such as numbers, strings, boolean as well as additional types like enum, any, never.
In TypeScript, we are declaring a variable with its type explicitly by appending the :
with the variable name followed by the type.
let decimal: number = 6;
let name: string = "Kanchan";
let anyvar: any = 4;
let unusable: void = undefined;
The reason adding types are:
- Types have proven ability to enhance code quality and understandability.
- It’s better for the compiler to catch errors than to have things fail at runtime.
- Types are one of the best forms of documentation we can have.
Q. What is TypeScript and why it is used for?
TypeScript is an object-oriented, open source programming language maintained and developed by Microsoft. It is developed to overcome the flaws of JavaScript. As a superset of JavaScript, TypeScript can be used to develop large JavaScript applications with support for modules and classes, ES6 features, Type-checking, API definition, JavaScript packaging support, class library, and more.
Q. What is the difference between TypeScript and JavaScript?
S.no | TypeScript | JavaScript |
---|---|---|
1. | Typescript is an object-oriented language. | JavaScript is a scripting language. |
2. | Static typing feature is available here. | Doesn’t support static typing. |
3. | TypeScript supports modules. | JavaScript doesn’t support modules. |
4. | It has an interface. | Doesn’t have any interface. |
5. | The optional parameter function is supported here. | JavaScript doesn’t support optional parameter function. |
Q. What is the advantage of TypeScript?
Here is a list of benefits developers can enjoy with the use of TypeScript.
- TypeScript supports optional static typing.
- Incredible code scalability due to interface oriented development.
- Compliance with ES-next.
- Enhances code readability and quality with Types.
- Use of advance compilers to check errors.
- It includes dependency injection, which offers great testing and controller based APIs.
- Extremely predictable and maintainable code-base.
- Implementation of SOLID design patterns into a language is easy here.
- Clean code generation due to static typing.
- Refactoring is easy and fasts with TypeScript tools.
Q. Which Object Oriented Terms Are Supported By Typescript?
TypeScript supports the following object oriented terms:
- Modules
- Classes
- Interfaces
- Data Types
- Member functions
Good article for interview