Skip to content

Commit 101be92

Browse files
committed
Book Updates
-add constants to 2.1
1 parent 6befff8 commit 101be92

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

book/chapter2.1.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ obj my_favorite_number = 69;
5656
obj _____a_variable_with_a_lot_of_underscores_____ = "A lot of underscores";
5757
obj MY_3_FAVORITE_FOODS = ["Cake", "Pizza", "Burgers"];
5858
```
59+
60+
## Constants
61+
62+
Additionally, there are constants. Much similar to variables, they can also store data. They store data in a non-modifyable form though, meaning we can never change a constant or it's data once it is created.
63+
64+
```
65+
stay X = 10;
66+
67+
X = 20; # this line causes an error
68+
```
69+
70+
It is preferred to keep a constant's name fully uppercase, as they are best used for values you use everywhere in your program.
71+
72+
```
73+
stay MAX_STORAGE_AMOUNT = 240; # this way, 'MAX_STORAGE_AMOUNT' stands out from 'max_storage_amount'
74+
```

0 commit comments

Comments
 (0)