1/10
These flashcards cover key concepts, definitions, and example code related to TypeScript as reviewed in the junior-level exam notes.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the default type of a variable in TypeScript if no type is assigned?
any
What does the as
keyword do in TypeScript?
Casts a value to a specific type.
What is the difference between let
and const
in TypeScript?
let
is for variables that can be changed and are in a local scope, while const
is for variables that can't be changed.
What will be the output of the code in question 4?
"five".
How do you define a function that does not return anything?
function logMessage(): void { console.log("Hello"); }
What does ?
mean in a function parameter?
It marks the parameter as optional.
How do you create a tuple type in TypeScript?
let myTuple: [string, number] = ["hello", 10];
What is the difference between unknown
and any
?
unknown
is for a variable of which the type is not known, while any
can be reassigned to any possible type.
What will happen if you try to reassign a readonly
property?
It will throw a compilation error.
What does 'typeof do in TypeScript?
Returns the JavaScript runtime type of a variable.