TypeScript Introduction and Overview Quiz

TypeScript
0 Passed
0% acceptance

Test your foundational knowledge with 40 questions on TypeScript—covering its purpose, differences from JavaScript, benefits, compilation, and real-world applications.

40 Questions
~80 minutes
1

Question 1

What is TypeScript?

A
A statically typed superset of JavaScript that compiles to plain JavaScript
B
A completely new language that replaces JavaScript
C
A browser extension for debugging
D
A minification tool for JavaScript
2

Question 2

Who created and maintains TypeScript?

A
Microsoft
B
Google
C
Facebook
D
Mozilla
3

Question 3

What is the primary purpose of TypeScript?

A
To add static typing to JavaScript for better tooling and error prevention
B
To make JavaScript run faster
C
To replace HTML and CSS
D
To disable dynamic features of JavaScript
4

Question 4

Can valid JavaScript code be used as TypeScript code?

A
Yes, because TypeScript is a superset of JavaScript
B
No, you must rewrite all code
C
Only if you disable strict mode
D
Only in Node.js
5

Question 5

What file extension is commonly used for TypeScript files?

A
.ts
B
.typescript
C
.js
D
.type
6

Question 6

Which command compiles a TypeScript file named app.ts?

shell
# In terminal
A
tsc app.ts
B
ts app.ts
C
compile app.ts
D
node app.ts
7

Question 7

What is a key difference between TypeScript and JavaScript?

A
TypeScript supports static type annotations; JavaScript does not
B
JavaScript supports classes; TypeScript does not
C
TypeScript cannot use npm packages
D
JavaScript runs only in browsers
8

Question 8

What happens to TypeScript type annotations during compilation?

A
They are removed, and only JavaScript code remains
B
They are converted to comments
C
They are sent to the browser
D
They become global variables
9

Question 9

Which feature is available in TypeScript but not in standard JavaScript?

A
Interfaces
B
Functions
C
Arrays
D
Promises
10

Question 10

Which code is valid in TypeScript but would cause a compile-time error if misused?

typescript
function greet(name: string): string {
      return "Hello, " + name;
    }
A
Type annotations like `name: string`
B
The return statement
C
String concatenation
D
Function declaration
11

Question 11

Can TypeScript prevent all runtime errors?

A
No, but it reduces many common errors like wrong property access or incorrect function arguments
B
Yes, completely
C
Only in strict mode
D
Only in React apps
12

Question 12

What is emitted when you compile a TypeScript file?

A
A JavaScript file with the same logic but no type information
B
A binary executable
C
A TypeScript definition file only
D
An HTML page
13

Question 13

How does TypeScript improve developer productivity?

A
By providing better autocompletion, navigation, and refactoring in IDEs
B
By making code run 10x faster
C
By reducing file size automatically
D
By replacing unit tests
14

Question 14

Why is TypeScript beneficial for large teams?

A
It acts as living documentation through type contracts and improves code consistency
B
It forces all developers to use the same IDE
C
It prevents git commits
D
It auto-generates unit tests
15

Question 15

Which of the following is a common benefit of static typing in TypeScript?

A
Catching misspelled property names at compile time
B
Increasing memory usage at runtime
C
Slowing down the development process
D
Requiring manual type declarations for every variable
16

Question 16

What happens if you enable strict mode in TypeScript?

A
The compiler enforces stricter type-checking rules, like noImplicitAny and strictNullChecks
B
All JavaScript features are disabled
C
Compilation becomes slower
D
Only .js files are allowed
17

Question 17

How does TypeScript support modern JavaScript features?

A
It compiles newer syntax (e.g., optional chaining) to older JavaScript for compatibility
B
It blocks all ES2020+ features
C
It only supports features from 2015
D
It requires Babel alongside it
18

Question 18

Which tooling feature is enhanced by TypeScript in VS Code?

A
Go to Definition, Find All References, and Rename Symbol
B
Browser DevTools integration
C
Network throttling
D
CSS grid visualization
19

Question 19

What is the minimal valid TypeScript program?

A
// empty file or any valid JavaScript statement
B
Must include an interface
C
Must declare types for all variables
D
Must export a class
20

Question 20

What does this TypeScript code do?

typescript
let count: number = 5;
    count = "hello"; // ❌
A
Causes a compile-time error because a string is assigned to a number variable
B
Runs successfully at runtime
C
Converts "hello" to NaN
D
Ignores the type annotation
21

Question 21

Which is a valid way to define a function with typed parameters in TypeScript?

typescript
// Option A
    function add(a: number, b: number): number {
      return a + b;
    }
A
function add(a: number, b: number): number { return a + b; }
B
function add(a, b) { return a + b; }
C
const add = (a, b) => a + b;
D
All of the above are valid, but only A includes type annotations
22

Question 22

What is the inferred type of name in this code?

typescript
const name = "Alice";
A
string
B
any
C
object
D
unknown
23

Question 23

Which file typically contains TypeScript compiler options?

A
tsconfig.json
B
package.json
C
webpack.config.js
D
.eslintrc
24

Question 24

What does this interface define?

typescript
interface User {
      name: string;
      age: number;
    }
A
A contract that any object assigned to User must have name (string) and age (number)
B
A class that can be instantiated
C
A runtime validation function
D
A database schema
25

Question 25

How does TypeScript help with refactoring?

A
Renaming a function updates all references safely across the codebase
B
It automatically rewrites logic
C
It prevents any code changes
D
It backs up your code before changes
26

Question 26

Why is explicit typing beneficial for API boundaries?

A
It documents expected inputs and outputs, reducing integration errors
B
It encrypts data
C
It increases network speed
D
It replaces API documentation
27

Question 27

What kind of error can TypeScript help prevent?

A
Calling a method that doesn’t exist on an object
B
Dividing by zero
C
Network timeouts
D
Memory leaks
28

Question 28

How does TypeScript support gradual migration from JavaScript?

A
You can rename .js to .ts and add types incrementally
B
You must convert all files at once
C
It only works with new projects
D
It requires rewriting in C++
29

Question 29

What is the benefit of using union types in TypeScript?

A
They allow a variable to accept more than one type, improving flexibility while maintaining safety
B
They force all values to be strings
C
They disable type checking
D
They increase bundle size
30

Question 30

How does TypeScript integrate with third-party libraries?

A
Via type declaration files (.d.ts), often from DefinitelyTyped or built-in
B
It cannot use npm packages
C
Only if the library is written in TypeScript
D
By rewriting the library
31

Question 31

What is the role of the TypeScript compiler (tsc)?

A
To type-check code and emit compatible JavaScript
B
To run TypeScript in the browser
C
To bundle CSS and images
D
To minify HTML
32

Question 32

What JavaScript version is this TypeScript code compiled to by default?

typescript
const result = numbers.map(n => n * 2);
A
Depends on the target setting in tsconfig.json (ES3 by default in older versions, but often ES2015+ now)
B
Always ES5
C
Always the latest ECMAScript
D
It doesn’t compile
33

Question 33

What happens if you run tsc on a file with a type error?

A
By default, JavaScript is still emitted unless --noEmitOnError is used
B
The program crashes
C
No output is created ever
D
It opens a browser
34

Question 34

Which command generates type declaration files (.d.ts) alongside JavaScript output?

A
tsc --declaration
B
tsc --types
C
tsc --emit-types
D
tsc --dts
35

Question 35

Can TypeScript compile to JavaScript that runs in older browsers?

A
Yes, by targeting ES5 or using polyfills for missing APIs
B
No, it only supports modern browsers
C
Only if you use React
D
Only in development mode
36

Question 36

Which frontend framework was originally built with TypeScript?

A
Angular
B
Vue 2
C
Svelte
D
jQuery
37

Question 37

Why is TypeScript popular for Node.js backends?

A
It helps manage complex data flows, API contracts, and large codebases with confidence
B
It replaces Express.js
C
It auto-generates databases
D
It compiles to Python
38

Question 38

How is TypeScript used in monorepos or design systems?

A
To share type definitions across packages, ensuring consistency and early error detection
B
To compress assets
C
To deploy to AWS
D
To disable linting
39

Question 39

Which company uses TypeScript at scale in its products?

A
All of the above: Microsoft, Google, Slack, Airbnb
B
Only Microsoft
C
Only startups
D
No major companies
40

Question 40

When might you choose not to use TypeScript?

A
For very small scripts, prototypes, or when team members lack familiarity and timeline is tight
B
For all production code
C
TypeScript is always required
D
Only in academic settings

QUIZZES IN TypeScript