summaryrefslogtreecommitdiffhomepage
path: root/README.md
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-05-18 14:18:04 +0200
committerJo-Philipp Wich <jo@mein.io>2021-05-18 16:09:36 +0200
commit5714705aee31a0d561b4cf1b8096bbe19e17a825 (patch)
tree1c249365983089fb249b1f109f13ed3a590863d0 /README.md
parent2c2e603204be7ec96cab7504e3ee6951412ad4bc (diff)
syntax: introduce `const` support
Introduce support for declaring constant variables through the `const` keyword. Variables declared with `const` follow the same scoping rules as `let` declared ones. In contrast to normal variables, `const` ones may not be assigned to after their declaration. Any attempt to do so will result in a syntax error during compilation. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'README.md')
-rw-r--r--README.md16
1 files changed, 15 insertions, 1 deletions
diff --git a/README.md b/README.md
index 55ac9c3..fc3c1da 100644
--- a/README.md
+++ b/README.md
@@ -154,9 +154,14 @@ through numeric operations, or explicitely, e.g. by invoking functions such as
Variable names must start with a letter or an underscore and may only contain
the characters `A`..`Z`, `a`..`z`, `0`..`9` or `_`. By prefixing a variable
-name with the keyword `let`, it is declared in the local function scope only
+name with the keyword `let`, it is declared in the local block scope only
and not visible outside anymore.
+Variables may also be declared using the `const` keyword. Such variables follow
+the same scoping rules as `let` declared ones but they cannot be modified after
+they have been declared. Any attempt to do so will result in a syntax error
+during compilation.
+
```javascript
{%
@@ -172,6 +177,15 @@ and not visible outside anymore.
print(a, "\n"); // outputs "2"
print(b, "\n"); // outputs nothing
+ const c = 3;
+ print(c, "\n"); // outputs "3"
+
+ c = 4; // raises syntax error
+ c++; // raises syntax error
+
+ const d; // raises syntax error, const variables must
+ // be initialized at declaration time
+
%}
```