Angular

TypeScript Basics

Primitive types, interfaces, union types, literal types, type assertions, type guards, narrowing

25 interview questionsยท
Junior
1

Which TypeScript primitive type represents a textual value?

Answer

The string type represents all textual values in TypeScript, whether delimited by single quotes, double quotes, or backticks for template literals. It is the appropriate type for storing text, names, messages, URLs, or any textual content in applications.

2

Which type to use for a variable that can contain any value without type checking?

Answer

The any type completely disables TypeScript type checking for a variable. It allows assigning any value and performing all operations without compilation errors. However, its use is discouraged as it eliminates the benefits of type safety.

3

Which type represents the absence of a return value in a function?

Answer

The void type indicates that a function does not return any meaningful value. It is used for functions that perform actions without producing a result, such as display or state modification functions. A void function can return undefined implicitly.

4

What is the main difference between null and undefined in TypeScript?

5

Which type to use for a value whose type is unknown and requires verification before use?

+22 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free