• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
Switch to Dark Mode

Variables and Data Types in TypeScript

This quiz will cover the topics related to variables and data types in TypeScript.

Last Updated : Feb 11, 2025
Discuss
Comments

Question 1

Which keyword is used to declare a variable with block scope in TypeScript?

  • A

    var

  • B

    let

  • C

    const

  • D

    Both b and c

Question 2

Which keyword is used to declare a variable with block scope in TypeScript?

  • A

    let allows reassignment, but const does not

  • B

    const allows reassignment, but let does not

  • C

    Both allow reassignment

  • D

    There is no difference

Question 3

What will be the output of the following code?

TypeScript
let a = 10;
a = "Hello";
console.log(a);


  • A

    Hello

  • B

    10

  • C

    Compilation error

  • D

    Undefined

Question 4

Which data type is NOT available in TypeScript?

  • A

    number

  • B

    boolean

  • C

    character

  • D

    undefined

Question 5

What does typeof null return in TypeScript?

  • A

    "null"

  • B

    "object"

  • C

    "undefined"

  • D

    "string"

Question 6

What is the any type used for in TypeScript?

  • A

    To allow variables to hold any type of value

  • B

    To restrict a variable to a single type

  • C

    To enforce strict type checking

  • D

    To define a variable without assigning a value

Question 7

What is the default type of a variable declared without an explicit type in TypeScript?

  • A

    any

  • B

    unknown

  • C

    string

  • D

    void

Question 8

What will be the output of the following code?

TypeScript
let x: unknown = "Hello";
console.log(x.length);


  • A

    5

  • B

    undefined

  • C

    Compilation error

  • D

    Runtime error

Question 9

Which type allows a variable to store either a number or a string?

  • A

    mixed

  • B

    any

  • C

    union

  • D

    multi

Question 10

What does the readonly modifier do in TypeScript?

  • A

    Prevents reassignment of a variable

  • B

    Prevents modification of a property after initialization

  • C

    Prevents a variable from being accessed

  • D

    Makes a variable null by default

Ready to go from coding beginner to development pro? Our DSA to Development Coding Guide has everything you need to crush coding interviews and ace real-world projects! Limited spots available!
Enroll Now and Transform Your Coding Skills! Also get 90% fee refund on completing 90% of the course in 90 days! Take the Three 90 Challenge today.

There are 10 questions to complete.

Take a part in the ongoing discussion