Skip to Content
Constant Variable

Suppose we are building a game, and we want to keep track of the item names and their in-game prices. We need some variables!

In many cases, you will only assign a variable once, i.e. store a value into it, and then use it without ever changing it. These are the cases where you should use a constant variable.

Constant variables are extremely easy to use in Emojicode:

3.14 โžก๏ธ pi
  • 3.14 is the value of the variable.
  • โžก๏ธ is the assignment operator.
  • pi is the name of the variable.

Here, the value on the left-hand side of the โžก๏ธ is stored into the pi constant variable.

Note: You cannot change a constant variable. If you try to reassign a constant variable, this will result in a compiler error.



Declare a constant named year with a value of the current year.

Folder Icon

Take this course for free

Already have an account?