Anuncios

Tambien hay una version en castellano de este post, click aca.

Anuncios

Welcome to the post, today we’ll talk about the different operators.

Anuncios

Arithmetic operators

OperatorDescription
+Addition
Subtraction
*Multiplication
/Division
\Integar division
~Negation
^Exponentiation
=Assign
Anuncios

These operators make basical mathematical operations and we can used it combined between they.

Anuncios

Concatenation operator

OperatorDescription
&Concatenate
Anuncios

This operator allows us to join two texts.

Anuncios

Relational operators

OperatorDescription
=Equal
<>Different
<Lesser than
>Greater than
<=Lesser or equal than
>=Greater or equal than
Anuncios

These operators compare two values ​​and return a boolean value. When satisfied, it returns true; otherwise it is false. For example, you can have these values:

30 <> 40
25 < 30
25 > 30
Anuncios

The first example returns a true value because they’re differents. The second example returns true too. Because of the first value is lesser than the second and the third example returns a false value because it isn’t satisfied the comparation.

Anuncios

Logical Operators

OperatorDescription
notTurn the value to inverse
andcheck if both values are the same
orcheck if one value is true
xorreturns false if both values are the same
eqvit’s similar to equal operator
impcheck implication between values
Anuncios

These operators evaluate between two boolean values and returns another boolean value. Let’s take a look for the following examples:These operators evaluate between two boolean values and returns another boolean value. Let’s take a look for the following examples:

true and true
true or false
not true
Anuncios

The first case returns a boolean value of true because both values are true. The following case returns a true value because only one is true and the final example returns a false value. Because always returns contrary value.

Anuncios

Others

OperatorDescription
isComparation between objects
Anuncios

This operator is used to check if an object is from some type of data. For example, we’ve the function isnumber to check if the object is a number. Let’s a look to an example, create a new file with the following code:

const value_1 = 10
const value_2 = 30
const value_3 = true
const value_4 = false

msgbox value_1 < value_2,,"Operators sample"
msgbox value_1 > value_2,,"Operators sample"
msgbox value_3 or value_4,,"Operators sample"
msgbox not value_3,,"Operators final"
Anuncios

First, we define four constants. The first two are with number values and the other two are boolean values. Then, with msgbox we’ll show the value returned by the operator. Let’s watch the first msgbox output:

Anuncios

This is true because value_1 is lesser than value_2. Let’s watch now the second msgbox:

Anuncios

Now, it’s false because value_1 is not greater than value_2. Let’s watch the third msgbox:

Anuncios

Again, this is true because only one of both values is true and this operator returns true with this condition. Let’s watch the final msgbox:

Anuncios

This returns false because this operator always inverts the received value. These operators are used in conditionals, loops or another functions where we must evaluate a condition.

Anuncios
Note: 
Excuse by the pictures but my laptop is in spanish.
Anuncios

In summary, we saw to the available operators in the language, what they’re, how to use it, the returned values, an example and where can be used it. I hope you’ve found it useful. You can follow me on this social networks:

Anuncios

Donatión

It’s for site maintenance, thanks!

$1.50