CARVIEW |
Variables and Data Types in TypeScript
This quiz will cover the topics related to variables and data types in TypeScript.
Question 1
Which keyword is used to declare a variable with block scope in TypeScript?
var
let
const
Both b and c
Question 2
Which keyword is used to declare a variable with block scope in TypeScript?
let allows reassignment, but const does not
const allows reassignment, but let does not
Both allow reassignment
There is no difference
Question 3
What will be the output of the following code?
let a = 10;
a = "Hello";
console.log(a);
Hello
10
Compilation error
Undefined
Question 6
What is the any type used for in TypeScript?
To allow variables to hold any type of value
To restrict a variable to a single type
To enforce strict type checking
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?
any
unknown
string
void
Question 8
What will be the output of the following code?
let x: unknown = "Hello";
console.log(x.length);
5
undefined
Compilation error
Runtime error
Question 9
Which type allows a variable to store either a number or a string?
mixed
any
union
multi
Question 10
What does the readonly modifier do in TypeScript?
Prevents reassignment of a variable
Prevents modification of a property after initialization
Prevents a variable from being accessed
Makes a variable null by default
There are 10 questions to complete.