Recall & Review
beginner
What is a global variable in TypeScript?
A global variable is a variable declared outside any function or block, accessible from anywhere in the code.
Click to reveal answer
beginner
How do you declare a global variable in TypeScript?
You declare a global variable by defining it outside any function or block, usually at the top of your file or in a separate global declaration file.
Click to reveal answer
beginner
What keyword is used to declare a variable that can be reassigned globally?
The
let keyword is used to declare a variable that can be reassigned. If declared globally, it is accessible throughout the program.Click to reveal answer
intermediate
What is the difference between
var and let when declaring global variables?var declares a global variable that attaches to the global object (like window in browsers), while let declares a block-scoped variable that does not attach to the global object.Click to reveal answer
intermediate
How can you declare a global variable type in TypeScript for use across multiple files?
You can declare global variable types by creating a
.d.ts file with a declare global block, then defining the variable type inside it.Click to reveal answer
Where should you declare a global variable in TypeScript?
✗ Incorrect
Global variables are declared outside any function or block so they can be accessed anywhere.
Which keyword declares a block-scoped global variable in TypeScript?
✗ Incorrect
let declares a block-scoped variable that can be global if declared outside blocks.What happens if you declare a global variable with
var in a browser environment?✗ Incorrect
var global variables attach to the window object in browsers.How do you declare a global variable type in TypeScript for multiple files?
✗ Incorrect
Global types are declared with
declare global in declaration files.Which keyword should you avoid for global variables due to hoisting and global object pollution?
✗ Incorrect
var can cause hoisting issues and pollutes the global object, so it's best to avoid it for globals.Explain how to declare a global variable in TypeScript and the difference between using
var and let.Think about where the variable lives and how it behaves in the global scope.
You got /3 concepts.
Describe how to declare global variable types in TypeScript for use across multiple files.
This helps TypeScript understand global variables in big projects.
You got /3 concepts.