TypeScript: Typed JavaScript Fundamentals
TypeScript: Typed JavaScript Fundamentals
Up to 20 questions, shuffled on every run
Welcome to the TypeScript Basics Quiz! This quiz covers fundamental TypeScript concepts, static typing, and type-safe programming best practices. Each question is multiple-choice, and you’ll find hints to help you along the way. Good luck!
Answer key and explanations20 questions
The quiz above draws 20 questions at random from these 30, so a second attempt will not be the same run. Everything in the pool is listed here.
What is the primary purpose of TypeScript?
AnswerTo provide static type checking for JavaScript code
Which command is used to compile a TypeScript file into JavaScript?
Answer`tsc`
How do you define an interface for a User object?
Answer`interface User { name: string; }`
What does the "any" type do?
AnswerIt disables type checking for a particular variable
What is a "Tuple" in TypeScript?
AnswerAn array with a fixed number of elements and known types
Which keyword is used to make an interface property optional?
Answer`?`
What is an "Enum"?
AnswerA collection of related and named constant numeric values
What does the "void" type signify when used on a function?
AnswerThe function performs an action but returns no value
How do you define a Union Type in TypeScript?
Answer`string | number`
What is the "unknown" type?
AnswerA safer type that requires a type check before any usage
What is the purpose of the "readonly" keyword?
AnswerTo prevent a property from being changed after assignment
What is "Generics" in TypeScript?
AnswerA way to create components that work with a variety of types
Which file contains the configuration for a TypeScript project?
Answer`tsconfig.json`
What is "Type Inference"?
AnswerWhen the compiler automatically detects a variable type
What is the "never" type used for?
AnswerFor functions that do not reach an end point or return
How do you extend an interface?
Answer`interface Admin extends User`
What is an "Abstract Class"?
AnswerA base class that cannot be instantiated directly
Which keyword is used to access the parent class constructor?
Answer`super()`
What is a "Type Guard"?
AnswerA check that narrows a type within a specific scope
What is the "as" keyword used for?
Answer`To tell the compiler to treat a value as a specific type`
What is the result of transpiling TypeScript to JavaScript?
AnswerA standard JavaScript file with all types removed
How do you declare a private property in a TypeScript class?
Answer`private name: string;`
What is "Literal Types"?
AnswerA type that can only hold a specific, exact value
What is "Intersection Type"?
AnswerA type that combines multiple types into a single one
What is the "protected" modifier?
AnswerIt makes properties visible to a class and its children
How do you define a function type in an interface?
Answer`myFunc(): void;`
What is "Namespace" in TypeScript?
AnswerA way to group related code and prevent collisions
What is the "keyof" operator?
AnswerIt creates a union type of all keys from an object type
What does "Strict Mode" in tsconfig do?
AnswerIt enables comprehensive checks for more robust code
What is the "!" operator (Non-null assertion)?
AnswerIt asserts that a value is not null or undefined








