Just like any other language, JavaScript uses the standard operators to perform any mathematical operation. Including the use of parenthesis rule also because they are mathematical rules you hardly find a programming language that run away from the conventional.

The following are the symbols and what are their respective roles in the JavaScript language:

+ = Addition

– = Subtraction

* = Multiplication

/ = Division

% = Modulus

— = Decrement

+ + = Increment

<SCRIPT LANGUAGE=”JavaScript” type=”text/JavaScript”>
<! –
var sum = 5 +5;
var subtraction = 5-5;
var multiplication; = 5 * 5;
var division = 5/5;
var mod = 5%5;
document.write (sum);
document.write (“</br>”);
document.write (subtraction);
document.write (“</br>”);
document.write (multiplication);
document.write (“</br>”);
document.write (division);
document.write (“</br>”);
document.write (mod);
/ / ->
</ SCRIPT>

Mathematical operators can be used on variables of type integer and decimal, its use in other types of data end up generating error anyway are not compatible. The only exception I have is if the addition (+) where the operator is also used to concatenate strings, check out the example below:

<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
<!–
var p1 = “text1″;
var p2 = “text2″;
var p3 = “text3″;
var vT = p1+p2+p3;
document.write (vT);
//–>
</SCRIPT>

An important item, as the plus sign is ambiguous is important to understand how it works. Often you need to concatenate two numbers in the same variable as String and it will be necessary to create a new one using string spacing, if this is not done the string will have the value of the sum of two values​​.

<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
<!–
var num1 = 600;
var num2 = 28;
var v1 = num1+num2;
var v2 = num1+” “+num2;
document.write (v1);
document.write (“</br>”);
document.write (v2);
//–>
</SCRIPT>

In the example above we see the difference in the variable v1 is stored the value of the sum of the two numbers already stored in the variable v2 is a string containing two values​​, this item can often go unnoticed in programming, so it is important to be aware of these peculiarities.

javascript

Want to test your code and still work with one of the most powerful tools for web development? Then download the free version already Scriptcase and start today to take advantage of all the benefits it can provide, download now and check.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.