diff --git a/curriculum/challenges/english/25-front-end-development/quiz-typescript/66f1ae758b77cfc3e4da6151.md b/curriculum/challenges/english/25-front-end-development/quiz-typescript/66f1ae758b77cfc3e4da6151.md index 031e77cc07e..f41f1c1a032 100644 --- a/curriculum/challenges/english/25-front-end-development/quiz-typescript/66f1ae758b77cfc3e4da6151.md +++ b/curriculum/challenges/english/25-front-end-development/quiz-typescript/66f1ae758b77cfc3e4da6151.md @@ -17,439 +17,454 @@ Answer all of the questions below correctly to pass the quiz. #### --text-- -Placeholder question +What is Typescript? #### --distractors-- -Placeholder distractor 1 +A framework used for system programming. --- -Placeholder distractor 2 +A database management tool. --- -Placeholder distractor 3 +A programming language used for styling websites. #### --answer-- -Placeholder answer +A superset of JavaScript that adds static typing. ### --question-- #### --text-- -Placeholder question +Why should TypeScript be used in a project? #### --distractors-- -Placeholder distractor 1 +It eliminates the need for testing in applications. --- -Placeholder distractor 2 +It is faster than all other programming languages. --- -Placeholder distractor 3 +It makes styling websites easier. #### --answer-- -Placeholder answer +It improves maintainability by adding type definitions to JavaScript. ### --question-- #### --text-- -Placeholder question +What language is TypeScript compiled down to? #### --distractors-- -Placeholder distractor 1 +Java --- -Placeholder distractor 2 +Python --- -Placeholder distractor 3 +C++ #### --answer-- -Placeholder answer +JavaScript ### --question-- #### --text-- -Placeholder question +What would be the output of the following code snippet? + +```ts +function sum(a: number, b: number): number { + return a + b; +} +console.log(sum(2, 3)); +``` #### --distractors-- -Placeholder distractor 1 +`2 + 3` --- -Placeholder distractor 2 +`undefined` --- -Placeholder distractor 3 +`Error: Type 'number' is not assignable to type 'string'` #### --answer-- -Placeholder answer +`5` ### --question-- #### --text-- -Placeholder question +What is the primary purpose of an interface in TypeScript? #### --distractors-- -Placeholder distractor 1 +To compile TypeScript code into JavaScript. --- -Placeholder distractor 2 +To create a new data type. --- -Placeholder distractor 3 +To create a new JavaScript Object. #### --answer-- -Placeholder answer +To define the structure of an object. ### --question-- #### --text-- -Placeholder question +Which of the following is NOT a basic primitive in TypeScript? #### --distractors-- -Placeholder distractor 1 +string --- -Placeholder distractor 2 +boolean --- -Placeholder distractor 3 +number #### --answer-- -Placeholder answer +array ### --question-- #### --text-- -Placeholder question +Which of the following correctly defines a literal type in TypeScript? #### --distractors-- -Placeholder distractor 1 +`let y: string;` --- -Placeholder distractor 2 +`let z: boolean;` --- -Placeholder distractor 3 +`let a: number[];` #### --answer-- -Placeholder answer +`let x: 5;` ### --question-- #### --text-- -Placeholder question +What is the primary purpose of the `type` keyword in TypeScript? #### --distractors-- -Placeholder distractor 1 +To declare variables. --- -Placeholder distractor 2 +To create classes. --- -Placeholder distractor 3 +To implement interfaces. #### --answer-- -Placeholder answer +To define custom types. ### --question-- #### --text-- -Placeholder question +Which of the following correctly defines a union type? #### --distractors-- -Placeholder distractor 1 +`type Result = Pass && Fail;` --- -Placeholder distractor 2 +`type Result = Pass & Fail;` --- -Placeholder distractor 3 +`type Result = Pass + Fail;` #### --answer-- -Placeholder answer +`type Result = Pass | Fail;` ### --question-- #### --text-- -Placeholder question +Which of the following capabilities is unique to `interface` and CANNOT be achieved using `type` in TypeScript? #### --distractors-- -Placeholder distractor 1 +Defining object shapes. --- -Placeholder distractor 2 +Creating union types. --- -Placeholder distractor 3 +Creating intersection types. #### --answer-- -Placeholder answer +Declaring class implementations. ### --question-- #### --text-- -Placeholder question +What is the primary purpose of using generics in TypeScript? #### --distractors-- -Placeholder distractor 1 +To implement inheritance between classes. --- -Placeholder distractor 2 +To define structure of an object. --- -Placeholder distractor 3 +To create a new data type. #### --answer-- -Placeholder answer +To write reusable code that can work with multiple types. ### --question-- #### --text-- -Placeholder question +Which of the following is a **proper example** of a generic function in TypeScript? #### --distractors-- -Placeholder distractor 1 +`function add(a: number, b: number): number { return a + b; }` --- -Placeholder distractor 2 +`function multiply(a: number, b: number): { return a * b; }` --- -Placeholder distractor 3 +`function getValue(value: any): any { return value; }` #### --answer-- -Placeholder answer +`function identity(value: T): T { return value; }` ### --question-- #### --text-- -Placeholder question +What is type narrowing in TypeScript? #### --distractors-- -Placeholder distractor 1 +Reducing the size of compiled JavaScript. --- -Placeholder distractor 2 +Limiting the number of types in a union. --- -Placeholder distractor 3 +Removing unused types from a TypeScript project. #### --answer-- -Placeholder answer +To write code that narrows down a union type to a more specific type. ### --question-- #### --text-- -Placeholder question +Which file is typically used to configure TypeScript compiler options? #### --distractors-- -Placeholder distractor 1 +`package.json` --- -Placeholder distractor 2 +`package.config.json` --- -Placeholder distractor 3 +`typescript.config.js` #### --answer-- -Placeholder answer +`tsconfig.json` ### --question-- #### --text-- -Placeholder question +What does the `target` option in the `tsconfig.json` file specify? #### --distractors-- -Placeholder distractor 1 +The version of TypeScript to use during compilation. --- -Placeholder distractor 2 +The target runtime environment (e.g., Node.js or browser) for the TypeScript code. --- -Placeholder distractor 3 +The specific module system to use for imports and exports. #### --answer-- -Placeholder answer +The ECMAScript version to which the TypeScript compiler will transpile the code. ### --question-- #### --text-- -Placeholder question +What does the `noImplicitReturns` option in the `tsconfig.json` file enforce? #### --distractors-- -Placeholder distractor 1 +It forces all functions to return a `number`. --- -Placeholder distractor 2 +It requires that all functions return either `true` or `false`. --- -Placeholder distractor 3 +It prevents using the `any` type in TypeScript code. #### --answer-- -Placeholder answer +It ensures all code paths in a function return a value. ### --question-- #### --text-- -Placeholder question +Which TypeScript option prevents implicit `any` types? #### --distractors-- -Placeholder distractor 1 +`noImplicitReturns` --- -Placeholder distractor 2 +`alwaysStrict` --- -Placeholder distractor 3 +`strictNullChecks` #### --answer-- -Placeholder answer +`noImplicitAny` ### --question-- #### --text-- -Placeholder question +What is the purpose of the `never` type in TypeScript? #### --distractors-- -Placeholder distractor 1 +To represent null or undefined. --- -Placeholder distractor 2 +To represent any possible value. --- -Placeholder distractor 3 +To represent a type that can be anything except null. #### --answer-- -Placeholder answer +To represent the type of values that never occur. ### --question-- #### --text-- -Placeholder question +What will be the output of the following TypeScript code? + +```ts +enum Color { + Red, + Blue, +} +console.log(Color.Red, Color.Blue); +``` #### --distractors-- -Placeholder distractor 1 +`Red Blue` --- -Placeholder distractor 2 +`1, 2` --- -Placeholder distractor 3 +`Red 2` #### --answer-- -Placeholder answer +`0 1` ### --question-- #### --text-- -Placeholder question +How can you specify that a function parameter is optional in TypeScript? #### --distractors-- -Placeholder distractor 1 +By using the `optional` keyword. --- -Placeholder distractor 2 +By setting a default value. --- -Placeholder distractor 3 +By using the `any` type. #### --answer-- -Placeholder answer +By adding a `?` after the parameter name