Search Header Logo

yash's Quiz

Authored by yash manuja

Professional Development

yash's Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct syntax to define an optional property in an interface?

property?: type;

property: type?;

property: ?type;

property: Optional<type>;

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is used to enforce a variable to only have a specific set of values?

enum

type

interface

const

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the result of the following TypeScript code?

let x: number = 10;

let y: string = "Hello";

x = y;

x will be assigned the value "Hello"

TypeScript will give a compile-time error because number cannot be assigned a string

The code will run without error and x will have the value "Hello"

TypeScript will automatically convert the string to a number

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to define a function type that accepts a string and returns a number?

(x: string) => number;

(x: string): number => {}

function(x: string): number;

type func = (x: string): number;

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following can NOT be a valid type in TypeScript?

string[]

Record<string, number>

string | number

[]string

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

True or False: Interfaces in TypeScript can merge declarations of the same name within the same scope.

True

False

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following TypeScript code?

type User = { name: string; age: number; };

const user: User = {

name: 'Alice',

age: 30,

role: 'Admin', // extra property };

TypeScript will throw an error because role is not part of User

TypeScript will throw an error because role is not a string

user will be valid and role will be added automatically to the User type

The code will run, but TypeScript will warn about the extra property

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?