Question · JavaScript and TypeScript course · Module 6: TypeScript Basics
Difference Between x?: string and x: string | undefined
What is the difference between x?: string and x: string | undefined in a function parameter?
Answer options
- There is no difference - both notations are equivalent
- x?: string allows omitting the argument when calling, while x: string | undefined requires explicitly passing a value (even undefined)
- x?: string automatically sets the default value to an empty string, while x: string | undefined does not
- x: string | undefined allows omitting the argument, while x?: string requires explicit passing
You can check the correct answer by solving this task in the CodeWorlds game.