What is Type Annotation in TypeScript?
A way to assign a default value to a variable
A method to explicitly declare the type of a variable
A feature that automatically assigns types to variables
A way to convert one type into another
What is Type Inference in TypeScript?
When TypeScript automatically determines the type of a variable
When TypeScript forces developers to specify types manually
A process of converting one type to another
A way to disable type checking
What will be the inferred type of the variable x in the following code?
TypeScript
What happens if you try to assign a string to a variable inferred as a number?
TypeScript
let x = 100;
x = "Hello";
The code compiles and runs without errors
TypeScript throws a compilation error
TypeScript changes the type of x to string
The value is automatically converted to a number
How do you explicitly declare a function’s return type in TypeScript?
function add(a: number, b: number) -> number {}
function add(a: number, b: number): number {}
function add(a: number, b: number) = number {}
function add(a: number, b: number) returns number {}
What will be the inferred return type of this function?
TypeScript
function greet() {
return "Hello, TypeScript!";
}
What will be the inferred type of the variable flag in the following code?
TypeScript
Which of the following types is inferred when a variable is declared without assignment?
TypeScript
How can you explicitly define a variable with multiple possible types?
let value: multiple<number, string> = 42;
let value = number | string = 42;
let value: number | string = 42;
let value: any = 42 | "hello";
What happens when you use strictNullChecks in TypeScript?
null and undefined are treated as normal values
null and undefined cannot be assigned to variables of other types unless explicitly allowed
TypeScript ignores null values in type checking
null and undefined behave like numbers
There are 10 questions to complete.
Take a part in the ongoing discussion
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4