Constants
Learn about storing unchangeable values.
What are Constants?
Constants are very similar to variables, with one major difference is that constants cannot change their values.
Declaring a Constant
The syntax for declaring a new constant is as the following:
The keyword
ثابت
(which means constant)The type of the constant
Constant TypeUnlike variables, constants can only be of type number
رقم
, stringمقطع
, or booleanمنطق
The name of the constant
The assignment symbol
=
The value of the constant (required)
Constant ValueThe value of a constant can only be a primitive value, such as
12
,"مرحبا بالعالم"
, orصحيح
A semicolon
؛
for ending the statement
An example of declaring a number constant of name باي and value 3.14:
ثابت رقم باي = 3.14؛
Using a Constant
Using a constant doesn't differ than using a variable at all.
An example of printing the value of a constant:
ثابت رقم باي = 3.14؛
أكتب(باي)؛