What is the output of this TypeScript code?
let count = 10; function showCount() { console.log(count); } showCount();
Global variables are accessible inside functions unless shadowed.
The variable count is declared globally and accessible inside showCount. So it prints 10.
What will this code print?
let message = "Hello"; function greet() { let message = "Hi"; console.log(message); } greet(); console.log(message);
Local variables with the same name shadow global ones inside functions.
The function prints the local message "Hi". Outside, the global message remains "Hello".
What error does this TypeScript code produce?
function update() { count = 5; let count = 10; } update();
Variables declared with let are not hoisted like var.
The code tries to assign to count before it is declared with let, causing a ReferenceError.
What is the output of this code?
let total = 0; function add(value: number) { total += value; } add(5); add(3); console.log(total);
Functions can change global variables if they don't redeclare them.
The function adds values to the global total. After two calls, total is 8.
In a TypeScript file treated as a module, which statement correctly declares a global variable accessible across multiple files?
Global variables shared across modules require declaration merging or global augmentation.
Option A correctly uses declare global in a declaration file to extend the global scope. Other options either create local variables or do not properly declare globals.