Skip to main content

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:

  1. The keyword ثابت (which means constant)

  2. The type of the constant

    Constant Type

    Unlike variables, constants can only be of type number رقم, string مقطع, or boolean منطق

  3. The name of the constant

  4. The assignment symbol =

  5. The value of the constant (required)

    Constant Value

    The value of a constant can only be a primitive value, such as 12, "مرحبا بالعالم", or صحيح

  6. 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؛
أكتب(باي)؛