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.14is the value of the variable.
➡️is the assignment operator.
piis 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.