Variables
A variable is a named representation of some section of memory. Variables are used to store values, one of the most fundamental part of any program. Some examples of declaring variables are:
let
is simply an alias for var
, they are exactly the same.
Strong v Weak
Many, now considered, "low-level" programming languages such as C are "strongly" typed. This means, you cannot change the type of a variable once it has been declared. This type is passed with the variable's decleration. For example the following is invalid:
Note: This works as well (since version v1.0.0-beta.51)
Some other languages such as JavaScript and Python, are "weakly" typed, this means you can change the type of a variable after it has been declared:
Cheddar uses both. Different programmers have different preferences on which typing is the best. Strong typing can be used as beneficial to avoid hard to debug bugs when typed automatically change. Weak typing can be helpful when quickly scripting. Cheddar suits both:
Note: If you're using a Cheddar version < 0.3 (cheddar -V
) implicit variables use the legacy var a := b
syntax.
Constants
Often times you want a variable that doesn't change, to be a "constant". Cheddar supports this, simply instead of the var
keyword, use const
:
Constants can also be strongly & weakly typed, except that the only time the type checking will ever happen is at the deceleration.
Last updated