Angular MCQs – TypeScript Basics

TypeScript is the backbone of Angular development, offering powerful features like static typing, interfaces, and classes that enhance JavaScript’s capabilities.

The following set of top multiple-choice questions (MCQs) on TypeScript Basics covers fundamental concepts such as data types, classes, interfaces, modules, functions, and more. These MCQs are designed to prepare you for Angular job interviews and technical assessments.

1.) What is TypeScript?

A) A superset of JavaScript that adds static typing
B) A JavaScript framework
C) A replacement for JavaScript
D) A database query language

Answer: Option A

Explanation: TypeScript is a strongly typed programming language that extends JavaScript by adding static typing, interfaces, and object-oriented features.

2.) Who developed TypeScript?

A) Google
B) Facebook
C) Microsoft
D) Apple

Answer: Option C

Explanation: TypeScript was developed by Microsoft and first released in 2012. It is a superset of JavaScript that adds static typing, making it easier to write and maintain large-scale applications.

3.) What file extension is used for TypeScript files?

A) .js
B) .ts
C) .jsx
D) .tsx

Answer: Option B

Explanation: TypeScript files use the .ts extension, whereas .tsx is used for TypeScript with React JSX.

4.) How do you compile a TypeScript file?

A) node filename.ts
B) tsc filename.ts
C) compile filename.ts
D) typescript filename.ts

Answer: Option B

Explanation: The TypeScript compiler (tsc) is used to compile .ts files into JavaScript.

5.) Which of the following is a key feature of TypeScript?

A) Object-oriented programming features
B) Dynamic typing
C) No support for JavaScript functions
D) Only works with Angular

Answer: Option A

Explanation: TypeScript supports object-oriented programming with features like classes, interfaces, and inheritance.

6.) Which keyword is used to declare a variable in TypeScript?

A) var
B) let
C) const
D) All of the above

Answer: Option D

Explanation: TypeScript allows variable declaration using var, let, and const, but let and const are preferred due to block-scoping.

7.) What is Type Inference in TypeScript?

A) Manually defining types for variables
B) Allowing TypeScript to automatically determine the type
C) A process for converting TypeScript to JavaScript
D) A debugging feature

Answer: Option B

Explanation: TypeScript has a powerful type inference system that automatically determines variable types based on assigned values.

8.) What is the default access modifier in TypeScript?

A) private
B) protected
C) public
D) readonly

Answer: Option C

Explanation: In TypeScript, class members are public by default unless specified otherwise.

9.) What does the enum type do in TypeScript?

A) Defines a set of named constant values
B) Creates an array
C) Defines a class
D) Represents a data type for decimal numbers

Answer: Option A

Explanation: The enum type in TypeScript allows defining a set of named constants, making the code more readable and maintainable.

10.) How can you ensure a variable can hold values of multiple types in TypeScript?

A) Using union types
B) Using interface
C) Using void
D) Using enum

Answer: Option A

Explanation: Union types (|) allow a variable to accept multiple types, e.g., let data: string | number;.

Leave a Reply

Your email address will not be published. Required fields are marked *