What’s the Difference Between Let, Var, and Const in JavaScript?

To be honest, the statements let, var, and const can all be used to create bindings.

In fact, the binding names created from each statement type can be evaluated together in a single expression.

let firstName = "Gregory ";
var middleName = "Booker ";
const lastName = "Power";

console.log(firstName + middleName + lastName);
// -> Gregory Booker Power

What is let in JavaScript?

For now, just understand that let is a statement that initiates the binding of a variable to a value.

What is var in JavaScript?

var (all lowercase) is short for variable. It was a statement used before 2015, and it has subtle differences compared to let.

Let’s just consider them the same thing because they do almost everything similarly, except for a few things.

What is const in JavaScript?

const (all lowercase) is short for constant.

It basically defines the variable as a constant binding which means it can’t be changed to anything else.

This also means that using the = operator to change this binding to grab something different won’t work.

You can’t reassign to a const variable.

Leave a Comment