Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Typescript Interview Questions

Introduction To Typescript interview questions And Answers

Typescript is an open source language which was developed by Microsoft. It acts as a superscript of JavaScript. It is mainly used when development is to be done for large applications. It can also be used when JavaScript applications are to be built on both client side and server side. It can be said as a language as well as a set of tools. It supports various JS libraries and is portable. Let us have a look at different questions which can be asked if you attend an Interview on Typescript.

Now, if you are looking for a job which is related to Typescript then you need to prepare for the Typescript Interview Questions. It is true that every interview is different as per the different job profiles but still to clear the interview you need to have a good and clear knowledge of Typescript. Here, we have prepared the important Typescript Interview Questions and answers which will help you get success in your interview.

Below are the 10 important Typescript Interview Questions and Answers that are frequently asked in an interview. these questions are divided into parts are as follows:

  • Part 1 – Typescript Interview Questions (Basic)
  • Part 2 – Typescript Interview Questions (Advanced)

Part 1 – Typescript Interview Questions (Basic)

This first part covers basic Typescript Interview Questions and Answers

Q1) Explain what is Typescript and how is it different from JavaScript?

Answer:
Typescript is a superscript of JavaScript and is used for development of large applications. It provides optional static typing, classes, and interfaces. It can be said as a language and also a set of tools. It helps developers to use highly productive tools and helps in code refactoring. The main differences between Typescript and JavaScript are:
Typescript supports classes which help the programmer to work more in an object-oriented way, while JavaScript uses reusable components with the help of functions and prototype-based inheritance. JavaScript does not have any interfaces on the other hand typescript has interfaces. Static typing is supported in Typescript while it is not supported in JavaScript. Typescript provides optional parameters, JavaScript does not.

Q2) Which are different data types that are supported by Typescript and explain how to implement inheritance?

Answer:
Typescript also supports data types provided by all other languages. It includes:
Boolean: This can have values as true or false
Number: This can be any number value
String: This can be any character value
Array: This can be a list of numbers together
Enum: This allows creating a user-defined data type.
Inheritance can be implemented in Typescript by using the extends keyword.
class Car {
public domestic:boolean;
constructor(public name: string) { }
}

class SUV extends Car {
constructor(name: string, domestic: boolean)
{
super(name);
this.domestic = true;
}
}

class Sedan extends Car {
constructor(name: string, domestic: boolean)
{
super(name);
this.domestic = false;
}
}

Let us move to the next Typescript Interview Questions.

Q3) Explain tsconfig.json file?

Answer:
This file is used to indicate that directory is a root of Typescript project. This file specifies that root files and compiler options are required to compile that particular project. This file can also be used to streamline the building of the project. Below sample can be taken as an example:
{
“compilerOptions”: {
“removeComments”: true,
“sourceMap”: true
},
“files”: [
“main.ts”,
“othermodule.ts”
] }

Q4) Explain Lambda/Arrow functions in Typescript?

Answer:
The arrow function acts like an additional feature in typescript and is also known as lambda function. This function is without a name.
var mulNum = (n1: number, n2: number) => n1 * n2;
In this example => is a lambda operator and (n1 * n2) is the body of function and n1,n2 are the parameters.
let addNum = (n1: number, n2: number): number => { return n1 + n2; }
let multiNum = (n1: number, n2: number): number => { return n1 * n2; }
let dividNum = (n1: number, n2: number): number => { return n1 / n2; }

addNum(10, 2);// Result – 12
multiNum(10, 2);// Result – 20
multiNum(10, 2);// Result – 5

Q5) What is Anonymous function?

Answer:
This function is declared without any named identifier to refer to it.
var anonyFunc = function (num1: number, num2: number): number {
return num1 + num2;
}
//RESULT
console.log(anonyFunc(10, 20)); //Return is 30

//RESULT
console.log(anonyFunc(10, “xyz”));
// error: This will throw an error as string is passed instead of an integer.

Part 2 – Typescript Interview Questions (Advanced)

Let us now have a look at the advanced Typescript Interview Questions.

Q6) How can a class defined in a module be used outside the module?

Answer:
Classes defined in a module are available within the module and cannot be accessed outside the module.
module Vehicle {
class Car {
constructor (
public make: string,
public model: string) { }
}
var audiCar = new Car(“Audi”, “Q7”);
}
var fordCar = Vehicle.Car(“Ford”, “Figo”);
The variable fordCar will give an error as the class Car is not accessible and the user needs to use export keyword for the classes.
module Vehicle {
export class Car {
constructor (
public make: string,
public model: string) { }
}
var audiCar = new Car(“Audi”, “Q7”);
}
var fordCar = Vehicle.Car(“Ford”, “Figo”);
This variable will now work as export is used to make Car accessible outside its module.

Q7) What are decorators and list some of the decorators in TypeScript?

Answer:
Decorators enable a user to modify a class and its members. It allows the user to add annotations and Metaprogramming syntax for carrying out class declarations and members. These were just released on an experimental basis. Decorators can be enabled using a command line or by editing tsconfig.json file. To enable decorators using command line following command should be used:
tsc –target ES5 –experimentalDecorators

Q8) How to compile a Typescript file?

Answer:
Following steps should be followed in order to compile a typescript file:
1) A user must check if Typescript engine is enabled or not. A user can go to the title bar and check for their username and select options
2) In the project navigator, select and right-click the TS files that are to be compiled.
3) Select compile to JavaScript
4) A user can add a script reference to this compiled Javascript file in HTML code
5) Once this is done user can go to command line tsc to compile.

Let us move to the next Typescript Interview Questions.

Q9) What are the interfaces in Typescript?

Answer:
The interface defines the syntax of any variable or entity. Interfaces define properties, methods, and various events. Here only members are declared. Interfaces are helpful in defining various members and helps in defining a structure for the deriving classes. Interfaces can be declared using the interface keyword.

Q10) Why is typescript called an optionally statically typed language?

Answer:
Typescript being optionally statically typed language means that compiler can ignore the type of variable. Using ‘any’ datatype user can assign any type of variable. Typescript will not throw any error.
var unknownType: any = 4;
unknownType = “Okay, I am a string”;
unknownType = false; // A boolean.
Using this any datatype can be declared.

Recommended Article

This has been a guide to List Of Typescript Interview Questions and Answers so that the candidate can crackdown these Typescript Interview Questions easily. Here in this post, we have studied about top Typescript Interview Questions which are often asked in interviews. You may also look at the following articles to learn more –

  1. HTML interview Questions – 40 Useful Questions
  2. Scala Interview Questions 
  3. Javascript Interview Questions | Most Useful
  4. Ruby Interview Questions

The post Typescript Interview Questions appeared first on EDUCBA.



This post first appeared on Best Online Training & Video Courses | EduCBA, please read the originial post: here

Share the post

Typescript Interview Questions

×

Subscribe to Best Online Training & Video Courses | Educba

Get updates delivered right to your inbox!

Thank you for your subscription

×