June 24, 2021


TriStudy Provide Free Online Tutorials about Programming languages,Digital Marketing, web designing, online earning, web hosting, WordPress etc

Conditions in Javascript

Conditions in java script

Conditions in java script

The if statement The if statement allows us to test whether an expression is equivalent to true or false, and to execute different code based on the result. For example, we can use the confirm function if we want to ask the client if his name is “Aadil 808.”

The other keyword can also be omitted if we only want a block of code to be executed if a certain statement is valid.

The== operator is used to determine whether two variables are identical. Also in JavaScript there is another equality function,===, which allows a strict contrast. It means that it will only be true if the two items that you equate are the same form as the same contents

For example:

Inequality operators can also be used to evaluate expressions. For example:

Using logical operators, two or more expressions can be evaluated together to check whether or not two expressions evaluate to be true together. Use the AND operator & & to test if two expressions are both valid. Use the OR operator to check if at least one of the expressions is true.

The NOT operator ! can also be used likewise:

The switch statement

The switch statement is similar to the C programming language switch statement, but it also supports strings. Choosing between more than two different options and running the same code for more than one option is using the switch statement. For example:

In this example, both trigger the first sentence, “Private” a “Sergeant,” “Commander” triggers the second sentence, and “Captain” triggers the third. The default keyword defines the action for this case (optional) if an unknown rank has been evaulated. To avoid the switch from executing the next code block, we must use the break statement between each code block.

Use of the switch declaration in general