Northcentral Technical College Introduction To Programming
10-152-310
Introduction to Programming with JavaScript NTC 10-152-310

Learning Plan 5 Constants in JavaScript

# Constants in JavaScript

#### File: /Learning Plan 5/constants.html

> OK, there really aren't true constants in JavaScript

### What's a Constant?

- A Constant is a value that isn't supposed to change while you are running your program. They are also known values that never change, like `PI`.
- They look a lot like variables, but since they shouldn't change we call them `constants`.

#### How do we do that in JavaScript?

- Um, well, you see, we can't. We just have to fake it.
- Most programming languages have a real way to do this so that you can declare a constant that the language will not allow to change.
- `JavaScript` does not have this mechanism, yet. We just use a different naming convention and put them in a different place.
- That's right we use a regular `var` declaration and have the variable name be in `ALL CAPS`. We also assign the value to a constant when we declare it.
- If we have a constant that is more than one word we use the underscore `(_)` to separate the words.
- Oh, one final thing, we need to declare constants before we declare variables.