else if js:conditional statement

Posted under javascript sample code On By mohammed.mutawe

else if js

Conditional statements are used extensively in programming languages, and because JavaScript supports all the advantages of operators, these features must be used correctly to understand them.

Conditional statements enable you to give the correct meaning to the code that you wrote, where you will get the real meaning of programming while using it, and because the logic language is basis of computers, else if js is the summary of this logic that will give main purpose of building the code.

You might write a lot of lines to computer and it takes orders from you about it and then the computer will bring you to a fork in the road and you tell it what to do and that’s what else if js does anyway.

 

Concepts

  • Definition.
  • How to use else if js.

 

Definition

The condition is determined between two options, and if one of them is true, it will be executed according to the data, and if it is false, it will do nothing but return the value of -1 anyway

and that’s exactly what else if js do:

<script>

if(condition)
{
   //Do something
}
else
{
   //return -1 or do an other method
}

</script>

 

 

How to use else if js

I’m going to simplify the meaning of conditional sentence and else if js into a text sentence, and then I’ll put it in code. The sentence is:

“If today is Sunday then I will go to work!”

Well I will define a variable for example let it be today and add a value to it and then I will put sentence “I will go to work!” Inside the condition and if the condition is met, he will print this sentence, otherwise he will tell me that today is not Sunday using else if js to become:

<script>
_today = "Sunday";

_sentence1 = "I will go to work!";
_sentence2 = "Today is not sunday! keep at home :)";

if(_today == "Sunday")
{
   document.write(_sentence1 );
}
else
{
  document.write(_sentence2 );
}

</script>

 

Precisely that’s it , you defined an variable with string value equal this condition then you put the compiler with quick test to tell you about this value then upon it will return exactly with value were been calculated!.

Most programming languages ​​use conditional statements, if not all, and this indicates the kind of identifiers that are attached to the environment of each language specifically.

 

Nesting

You can also use nest and this is done by including more than one condition clause within the main condition clause, and you can narrow the system of possibilities in the conditional clauses to reach the narrowest possibility that will return to you the result you want during the condition, as else if js provides this like other programming languages:

<script>
bool x = true;
var anValue = 16;

if(x)
{
  if(anValue == 16)
{
   document.write("Congratulation! ,you accessed Block Nesting!");
}
}
else{
 //return -1
}
</script>

 

 

References

Leave a comment

Your email address will not be published. Required fields are marked *