When programming in any language conditionals are fundamental to develop programming logic, so it is essential to understand its operation.

In JavaScript, one of the most used is the command IF, as it is possible to perform a given action from a given condition.

<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
<!–
if (5 == 5) {
document.write (“Both are number 5.”);
}
//–>
</SCRIPT>

In the above example, the write command will be triggered only if the conditional is true, as is the case. These fixed values ​​can still be changed by variables and thus the IF command can be executed validating them. If the comparison were not true the code simply would not run.

Along with yet another IF command is widely used, the ELSE. It will be triggered when the conditional result in a false judgment, as shown below.

<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
<!–
if (10 == 5) {
document.write (“Both are number 5.”);
} else {
document.write (“Both are different.”);
}
//–>
</SCRIPT>

In the above case the result displayed on the screen would be “Both are different.”.

The standard syntax of the IF and ELSE command is exactly like that of several other languages ​​in Javascript but still have another form of writing that is known as IF ELSE summarized, check out:

<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
<!–
document.write (“Both“);
document.write (5 == 5 ? “are” : “aren´t”);
document.write (” number 5”);
//–>
</SCRIPT>

Using the characters “?” And “:” is it possible to create a sentence in a single line in a much more simple and quick. This syntax type is not used when there is a large information processing within the conditional, otherwise is indicated using the normal syntax.

javascript

This is one of several important items that a good web programmer must understand and master, in addition, have a good grip on tool development is also key. Therefore, know the e-learning section on our website to know more about Scriptcase and how it can help you program with much more agility.

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.