rhai/doc/src/language/constants.md
2020-06-20 12:06:17 +08:00

447 B

Constants

{{#include ../links.md}}

Constants can be defined using the const keyword and are immutable.

Constants follow the same naming rules as [variables].

const x = 42;
print(x * 2);       // prints 84
x = 123;            // <- syntax error: cannot assign to constant

Constants must be assigned a value, not an expression.

const x = 40 + 2;   // <- syntax error: cannot assign expression to constant