Skip to main content

Operators

Arithmetic Operators#

In LemonScript, there are a variety of operations such as +, -, * and /. Here is a list of all of them and what they do:

  • + - The plus operator can add a number or string to another number or string. For example 5 + 6 will return 11, and "Hi I'm " + "Bob" will return Hi I'm Bob. If either value is a string, it'll treat both values a string.

  • - - The minus operator can only subtract a number from another. For example 13.6 - 7.2 will return 6.4.

  • * - The multiplication operator can either multiply two numbers, for example 4 * 7 will return 28, or a string multiplied by a number, for example "hi" * 3 will return hihihi.

  • / - The divide operator can only divide a number from another number, for example 12 / 3 will return 4.

  • % - The modulus operator returns the remainder when a number is divided by another number. For example, 14 % 4 will return 2 because the highest multiple of 4 is 12, and 14 - 12 is 2.

  • ^ - The caret operator exponentializes a number to another number. For example 2 ^ 3 will return 8. Other types will throw an error.

Comparison Operators#

These operators return a boolean value (true or false) when comparing two expressions.

  • < or <= - The less or less or equal than operators check two numbers to another, and if they're less or equal. For example, 4 < 5 returns true, but 14 < 8 is false. The <= operator does the same thing, but also checks for equality, i.e 6 <= 6 is true.

  • > or >= - The greater or greater or equal than operators check two numbers to another, and if they're greater or equal. For example, 12 > 6 returns true, but 14 > 12 is false. The >= operator does the same thing, but also checks for equality.

  • == - The equals operator checks if two values have the same type, and the same value. For example, "hello" == "hello" is true, but "5" == 5 or 23 == 41.2 are not.