JavaScript in 60 Seconds

Const

The const keyword is similar to let but with some key differences.

Const keyword

Const is how we declare a constant, meaning a variable that is not supposed to change. In fact, JS will throw an error if you try to change it.

const name = "adam";

Now if we tried to change the variable, we see an error:

const age = 65; age = 30;

If you use the const keyword, then you must set a value.

Exercise: Now you try it.

// resolve the error const x;
// resolve the error const age = 5; age = 10;

Nice job! On to the next lesson.