---
title: "TypeScript: Typed JavaScript Fundamentals"
description: "Test your knowledge of TypeScript fundamentals with a quiz covering static typing, interfaces, generics, type guards, enums, classes, advanced types, and TypeScript best practices."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/typescript-fundamentals-quiz
---

# TypeScript: Typed JavaScript Fundamentals

Welcome to the TypeScript Basics Quiz! This quiz covers fundamental TypeScript concepts, static typing, and type-safe programming best practices. Each question is multiple-choice, and you'll find hints to help you along the way. Good luck!

## Questions

### 1. What is the primary purpose of TypeScript?

- To increase the execution speed of the browser engine
- To provide static type checking for JavaScript code
- To eliminate the need for CSS and HTML in development
- To automate the management of remote database servers

**Hint:** It adds something JavaScript is missing.

### 2. Which command is used to compile a TypeScript file into JavaScript?

- `npm start`
- `tsc`
- `node --compile`
- `ts-build`

**Hint:** TypeScript Compiler.

### 3. How do you define an interface for a User object?

- `type User = { name: string; }`
- `interface User { name: string; }`
- `class User { name: string; }`
- `struct User { name: string; }`

**Hint:** Use the "interface" keyword.

### 4. What does the "any" type do?

- It restricts a variable to only holding string data
- It disables type checking for a particular variable
- It allows a variable to be assigned only a null value
- It creates a constant that cannot be changed later

**Hint:** It turns off the safety features.

### 5. What is a "Tuple" in TypeScript?

- An array that automatically grows as items are added
- An array with a fixed number of elements and known types
- A function that returns two different data types at once
- A variable that can hold a string or a number selectively

**Hint:** A list with a fixed number of elements and types.

### 6. Which keyword is used to make an interface property optional?

- `!`
- `?`
- `void`
- `null`

**Hint:** The punctuation mark for a question.

### 7. What is an "Enum"?

- A built-in method for encrypting sensitive string data
- A collection of related and named constant numeric values
- A specific type of loop used to iterate through objects
- A function that executes itself immediately upon creation

**Hint:** A set of named constants.

### 8. What does the "void" type signify when used on a function?

- The function will terminate the program with an error
- The function performs an action but returns no value
- The function body has been left empty by the developer
- The function is only accessible within its current class

**Hint:** The function does its job but gives nothing back.

### 9. How do you define a Union Type in TypeScript?

- `string & number`
- `string | number`
- `string + number`
- `string [] number`

**Hint:** The "pipe" symbol.

### 10. What is the "unknown" type?

- A placeholder for variables that will be soon deprecated
- A safer type that requires a type check before any usage
- A type used to represent variables that have been deleted
- A specialized type for handling error objects in catches

**Hint:** A safer version of "any".

### 11. What is the purpose of the "readonly" keyword?

- To ensure a property cannot be accessed by outside files
- To prevent a property from being changed after assignment
- To optimize the loading speed of large data structures
- To mark a variable for inclusion in the browser storage

**Hint:** It prevents changes.

### 12. What is "Generics" in TypeScript?

- A library of pre-written functions for common web tasks
- A way to create components that work with a variety of types
- A tool for generating random data for testing applications
- A method for translating TypeScript into different languages

**Hint:** Creating components that work over a variety of types.

### 13. Which file contains the configuration for a TypeScript project?

- `package.json`
- `tsconfig.json`
- `typescript.json`
- `.ts-settings`

**Hint:** ts-config.

### 14. What is "Type Inference"?

- When a developer explicitly defines a variable as a string
- When the compiler automatically detects a variable type
- A technique for forcing one data type into another type
- A process for removing all type information from a file

**Hint:** TypeScript guessing the type.

### 15. What is the "never" type used for?

- For variables that are initialized with a null value
- For functions that do not reach an end point or return
- For components that are not intended to be reused
- For code that is executed only during the testing phase

**Hint:** For values that will never occur.

### 16. How do you extend an interface?

- `interface Admin + User`
- `interface Admin extends User`
- `interface Admin : User`
- `interface Admin is User`

**Hint:** Use the "extends" keyword.

### 17. What is an "Abstract Class"?

- A class that is hidden from other modules in the project
- A base class that cannot be instantiated directly
- A class that only contains static methods and constants
- A class designed to represent visual shapes in a UI

**Hint:** A class that cannot be instantiated on its own.

### 18. Which keyword is used to access the parent class constructor?

- `parent()`
- `super()`
- `base()`
- `this.constructor()`

**Hint:** Think "Super".

### 19. What is a "Type Guard"?

- A security mechanism that prevents unauthorized code access
- A check that narrows a type within a specific scope
- A function that validates that a user is logged in
- A variable that stores the current state of an interface

**Hint:** It narrows down a type within a block of code.

### 20. What is the "as" keyword used for?

- `To rename a variable for use in a different file`
- `To tell the compiler to treat a value as a specific type`
- `To import a specific module into the global scope`
- `To create a loop that iterates through an array`

**Hint:** Type Assertion.

### 21. What is the result of transpiling TypeScript to JavaScript?

- A compressed file that executes faster in the browser
- A standard JavaScript file with all types removed
- An encrypted file that is unreadable to human developers
- A binary file that runs directly on the server hardware

**Hint:** The types disappear.

### 22. How do you declare a private property in a TypeScript class?

- `hidden name: string;`
- `private name: string;`
- `#name: string;`
- `internal name: string;`

**Hint:** The "private" keyword.

### 23. What is "Literal Types"?

- A type that allows any string or number to be stored
- A type that can only hold a specific, exact value
- A type used for documentation in large-scale projects
- A type that can be changed by the user at runtime

**Hint:** The type is a specific value.

### 24. What is "Intersection Type"?

- A type that can be one of several different types
- A type that combines multiple types into a single one
- A type that is used to connect two separate databases
- A type that prevents a function from being executed

**Hint:** Combining multiple types into one.

### 25. What is the "protected" modifier?

- It makes the property accessible to everyone globally
- It makes properties visible to a class and its children
- It encrypts the property so it cannot be viewed in JS
- It prevents the property from being deleted or removed

**Hint:** Visible to the family.

### 26. How do you define a function type in an interface?

- `myFunc: void;`
- `myFunc(): void;`
- `function myFunc(): void;`
- `def myFunc(): void;`

**Hint:** name(params): returnType

### 27. What is "Namespace" in TypeScript?

- A way to organize files within the operating system
- A way to group related code and prevent collisions
- The specific URL where your project is hosted online
- A specialized database for storing key-value pairs

**Hint:** Grouping related code.

### 28. What is the "keyof" operator?

- It checks if a specific key is present in an object
- It creates a union type of all keys from an object type
- It renames the primary key of a database table record
- It exposes a variable that was marked as private

**Hint:** It extracts the keys.

### 29. What does "Strict Mode" in tsconfig do?

- It prevents the code from running on mobile browsers
- It enables comprehensive checks for more reliable code
- It forces all variable names to be written in all caps
- It automatically deletes code that contains any errors

**Hint:** It makes the compiler very picky.

### 30. What is the "!" operator (Non-null assertion)?

- It indicates that a variable is not used in the file
- It asserts that a value is not null or undefined
- It triggers an immediate error if a variable is empty
- It makes a variable available to all other functions

**Hint:** You are telling the compiler: "Trust me, it exists".
