TS PlaygroundLearnJavaScriptVariables
javascript/beginner

Variables

Learn the difference between var, let, and const in TypeScript.


Variables in TypeScript

TypeScript inherits JavaScript's three ways to declare variables, but const and let are almost always preferred over var.

const

Use const when the binding won't be reassigned. It's the default choice.

const greeting = "Hello, World!";

TypeScript infers the type automatically — greeting is string.

let

Use let when you need to reassign the variable later.

let count = 0;
count = count + 1; // ✓

var — avoid it

var has function scope (not block scope) and can cause subtle bugs. Ignore it.


Your task

Declare a const named greeting with the value "Hello, World!" and export it so the tests can check it.

export const greeting = "...";
// Declare an exported constant named 'greeting'
// with the value "Hello, World!"

Click Run Tests to see results
Functions