Multiple choice practice

TypeScript MCQ questions

Take a short practice test with instant feedback, then revise every question with its answer and the reason behind it.

Questions
105
From lessons
85
Your last test
—

Practice test

TypeScript practice testMultiple choice Question 1 of 10

What does the override keyword add?

Score so far: 0/0

All questions with answers

  1. What does the TypeScript compiler output?

    • AMachine code
    • BJavaScript
    • CWebAssembly
    • DBytecode for a TS VM
    Show answer

    Answer: B. JavaScript

    TypeScript compiles (transpiles) to plain JavaScript with the types removed.

  2. Which type accepts any value but forces you to check it before use?

    • Aany
    • Bunknown
    • Cnever
    • Dobject
    Show answer

    Answer: B. unknown

    unknown is the type-safe counterpart of any.

  3. What is the type of a function that always throws?

    • Avoid
    • Bundefined
    • Cnever
    • Dnull
    Show answer

    Answer: C. never

    never means the function never returns normally.

  4. How do you mark a property as optional?

    • Aname!: string
    • Bname?: string
    • Coptional name: string
    • Dname: string?
    Show answer

    Answer: B. name?: string

    The ? after the name makes it optional (type string | undefined).

  5. Which describes "a string or a number"?

    • Astring & number
    • Bstring | number
    • Cstring, number
    • D[string, number]
    Show answer

    Answer: B. string | number

    | is a union. & is an intersection; [a, b] is a tuple.

  6. What is the type of x?

    TypeScript Illustrative
    const x = 'hello';
    
    • Astring
    • B"hello"
    • Cany
    • DString
    Show answer

    Answer: B. "hello"

    const with a primitive literal infers the literal type.

  7. Which utility type makes every property optional?

    • ARequired<T>
    • BReadonly<T>
    • CPartial<T>
    • DPick<T, K>
    Show answer

    Answer: C. Partial<T>

    Partial<T> maps every property to optional.

  8. Which utility type creates a type with only some keys?

    • AOmit<T, K>
    • BPick<T, K>
    • CRecord<K, T>
    • DExtract<T, U>
    Show answer

    Answer: B. Pick<T, K>

    Pick keeps the listed keys; Omit removes them.

  9. What does keyof { id: number; name: string } produce?

    • A"id" | "name"
    • Bnumber | string
    • C["id", "name"]
    • Dstring
    Show answer

    Answer: A. "id" | "name"

    keyof gives a union of the property names.

  10. What error does this produce?

    TypeScript Illustrative
    function double(n: number) { return n * 2; }
    double('4');
    
    • ANone
    • BType "string" is not assignable to type "number"
    • CMissing return type
    • DCannot redeclare variable
    Show answer

    Answer: B. Type "string" is not assignable to type "number"

    The parameter is typed number, so passing a string is a compile error.

  11. Which keyword narrows a union of class instances?

    • Atypeof
    • Binstanceof
    • Ckeyof
    • Das
    Show answer

    Answer: B. instanceof

    instanceof checks the prototype chain; typeof works for primitives.

  12. Which syntax declares a generic function?

    • Afunction id(T)(x: T)
    • Bfunction id<T>(x: T): T
    • Cfunction id[T](x: T)
    • Dgeneric function id(x)
    Show answer

    Answer: B. function id<T>(x: T): T

    Type parameters go in angle brackets after the name.

  13. What does "strict": true enable?

    • AOnly noImplicitAny
    • BA family of strict checks including strictNullChecks
    • CES strict mode only
    • DFaster compilation
    Show answer

    Answer: B. A family of strict checks including strictNullChecks

    It turns on noImplicitAny, strictNullChecks, strictFunctionTypes and more.

  14. With strictNullChecks, can null be assigned to a string variable?

    • AYes
    • BNo, unless the type includes null
    • COnly in classes
    • DOnly with let
    Show answer

    Answer: B. No, unless the type includes null

    null and undefined must be listed explicitly: string | null.

  15. Which is true about interfaces?

    • AThey exist at runtime
    • BThey can be merged by declaring them twice
    • CThey cannot extend other interfaces
    • DThey can describe unions
    Show answer

    Answer: B. They can be merged by declaring them twice

    Declaration merging combines interfaces with the same name; type aliases cannot merge.

  16. What does a readonly property prevent?

    • AReading it
    • BReassigning it after initialisation
    • CSerialising it
    • DInheriting it
    Show answer

    Answer: B. Reassigning it after initialisation

    readonly is a compile-time check against reassignment.

  17. Which file configures the TypeScript compiler?

    • Apackage.json
    • Btsconfig.json
    • Cts.config.js
    • D.tsrc
    Show answer

    Answer: B. tsconfig.json

    tsconfig.json holds compilerOptions, include and exclude.

  18. What does Record<string, number> describe?

    • AAn array of numbers
    • BAn object with string keys and number values
    • CA tuple
    • DA Map
    Show answer

    Answer: B. An object with string keys and number values

    Record<K, V> builds an object type from key and value types.

  19. What is the return type of an async function that returns a number?

    • Anumber
    • BPromise<number>
    • CAsync<number>
    • Dvoid
    Show answer

    Answer: B. Promise<number>

    Async functions always return a promise.

  20. Which enum alternative avoids generated JavaScript?

    • AA class with static fields
    • BA union of string literals
    • CA namespace
    • DA WeakMap
    Show answer

    Answer: B. A union of string literals

    Literal unions are type-only; enums emit an object at runtime (except const enums).

  21. What does <T extends { id: number }> mean?

    • AT must be exactly { id: number }
    • BT can be any type that has a numeric id
    • CT inherits from a class called id
    • DT is optional
    Show answer

    Answer: B. T can be any type that has a numeric id

    extends sets a minimum shape; T may have more properties.

    From the lesson: Generics
  22. What happens to TypeScript types when the code is compiled?

    • AThey are checked at runtime
    • BThey are removed, leaving plain JavaScript
    • CThey become comments
    • DThey are sent to the browser
    Show answer

    Answer: B. They are removed, leaving plain JavaScript

    Types exist only at compile time.

    From the lesson: Introduction to TypeScript
  23. Every valid JavaScript program is also valid TypeScript syntax.

    • ATrue
    • BFalse
    Show answer

    Answer: A. True

    TypeScript is a superset of JavaScript (though type checking may report errors).

    From the lesson: Introduction to TypeScript
  24. Who created TypeScript?

    • AGoogle
    • BMeta
    • CMicrosoft
    • DMozilla
    Show answer

    Answer: C. Microsoft

    Microsoft released TypeScript in 2012.

    From the lesson: Introduction to TypeScript
  25. When does JavaScript usually reveal a type mistake?

    • AWhile typing
    • BAt compile time
    • CWhen the faulty line runs
    • DNever
    Show answer

    Answer: C. When the faulty line runs

    JavaScript is dynamically typed.

    From the lesson: JavaScript vs TypeScript