Definition
Which statement best describes TypeScript in relation to JavaScript?
- A superset of JavaScript that adds static typing
- A subset of JavaScript that removes features
- A browser-only runtime for JavaScript
- A CSS preprocessor for styling
- A JSON schema validator
Early error detection
When you write let age: string = 42 in TypeScript, what advantage is demonstrated compared to plain JavaScript?
- It catches type-related errors before running the code
- It guarantees the code will never crash at runtime
- It automatically converts numbers to strings at runtime
- It makes the code execute faster in all engines
- It removes the need for testing entirely
Type annotations syntax
Which TypeScript declaration correctly annotates a numeric variable initialized to 5?
- let count: number = 5;
- let count: num = 5;
- let count = number 5;
- let count: Number = '5';
- let count: string = 5;
Object shapes with interfaces
Given interface User { name: string; active: boolean } and const u: User = { name: 'Ana', active: true }, what is the main advantage of using the interface here?
- It documents and enforces the structure of objects
- It encrypts user data by default
- It automatically persists objects to a database
- It makes the program multithreaded
- It removes the need for any comments or docs
Union types prevent invalid values
If type Status = 'loading' | 'success' | 'error' and you write let s: Status = 'loaded', what does TypeScript do?
- Produce a compile-time error about an invalid type
- Silently convert 'loaded' to 'loading'
- Log a warning only at runtime
- Wrap the value in an object automatically
- Accept it because strings are allowed
Type inference
In let name = 'Pat', what type does TypeScript infer for the variable name?
- string
- number
- any
- boolean
- null
The 'any' type trade-off
Which TypeScript type should you avoid overusing because it disables most type checking and safety?
- any
- unkown
- void
- never
- Enum
Transpilation target
Before running in a browser or a JavaScript runtime, TypeScript code is typically compiled into which language?
- JavaScript
- WebAssembly
- HTML
- Bytecode
- Javscript
Generics preserve types
Given function identityu003CTu003E(value: T): T { return value; }, what benefit do generics provide in this example?
- They preserve and return the exact input type without casts
- They convert all inputs to strings
- They hide types at compile time (type erasure only)
- They eliminate the need for interfaces and types
- They guarantee faster execution speed
Configuration and strictness
What is the purpose of a TypeScript configuration file that sets options like 'target' and 'strict' for a project?
- To control compiler behavior such as output JS version and type-checking strictness
- To define HTTP routes for the server
- To store secret environment variables
- To declare CSS color themes
- To bundle and compress images