TypeScript 101: Why and How It Improves JavaScript Quiz

  1. Definition

    Which statement best describes TypeScript in relation to JavaScript?

    1. A superset of JavaScript that adds static typing
    2. A subset of JavaScript that removes features
    3. A browser-only runtime for JavaScript
    4. A CSS preprocessor for styling
    5. A JSON schema validator
  2. Early error detection

    When you write let age: string = 42 in TypeScript, what advantage is demonstrated compared to plain JavaScript?

    1. It catches type-related errors before running the code
    2. It guarantees the code will never crash at runtime
    3. It automatically converts numbers to strings at runtime
    4. It makes the code execute faster in all engines
    5. It removes the need for testing entirely
  3. Type annotations syntax

    Which TypeScript declaration correctly annotates a numeric variable initialized to 5?

    1. let count: number = 5;
    2. let count: num = 5;
    3. let count = number 5;
    4. let count: Number = '5';
    5. let count: string = 5;
  4. 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?

    1. It documents and enforces the structure of objects
    2. It encrypts user data by default
    3. It automatically persists objects to a database
    4. It makes the program multithreaded
    5. It removes the need for any comments or docs
  5. Union types prevent invalid values

    If type Status = 'loading' | 'success' | 'error' and you write let s: Status = 'loaded', what does TypeScript do?

    1. Produce a compile-time error about an invalid type
    2. Silently convert 'loaded' to 'loading'
    3. Log a warning only at runtime
    4. Wrap the value in an object automatically
    5. Accept it because strings are allowed
  6. Type inference

    In let name = 'Pat', what type does TypeScript infer for the variable name?

    1. string
    2. number
    3. any
    4. boolean
    5. null
  7. The 'any' type trade-off

    Which TypeScript type should you avoid overusing because it disables most type checking and safety?

    1. any
    2. unkown
    3. void
    4. never
    5. Enum
  8. Transpilation target

    Before running in a browser or a JavaScript runtime, TypeScript code is typically compiled into which language?

    1. JavaScript
    2. WebAssembly
    3. HTML
    4. Bytecode
    5. Javscript
  9. Generics preserve types

    Given function identityu003CTu003E(value: T): T { return value; }, what benefit do generics provide in this example?

    1. They preserve and return the exact input type without casts
    2. They convert all inputs to strings
    3. They hide types at compile time (type erasure only)
    4. They eliminate the need for interfaces and types
    5. They guarantee faster execution speed
  10. Configuration and strictness

    What is the purpose of a TypeScript configuration file that sets options like 'target' and 'strict' for a project?

    1. To control compiler behavior such as output JS version and type-checking strictness
    2. To define HTTP routes for the server
    3. To store secret environment variables
    4. To declare CSS color themes
    5. To bundle and compress images