Figure1: above figure is output of arithmetic operator in which five operator are described.
earlier we have seen a single equal (=) sign which sets a value, here you will see double equal sign (==) that used of comparing two values or variables. Comparisons are used to check the basically relationship between variables and/or values. Comparison operators are always used inside conditional statements and prints to either true or false. Listed section will clear the concept of comparison operator:
Listing 2: Script of Comparison Operator
Figure 2: Above figure is output of comparison operator in which after comparing the values result obtained is printed false for this program.
- First one is “&&” operator which is called Logical AND operator. If both the operands are non zero then condition becomes true. (A && B) is true.
- Second one is “||” operator which is called Logical OR Operator. If any of the two operands are non zero then condition becomes true. (A || B) is true.
- Third one is “!” operator which is called not operator. When a variable is not being used or is not available for processing we used null operator or logical not operator. If you want to revert the condition, apply the logical not operator variable you can use logical not operator which is “!”. Its syntax is: “!a” or “!value1” following script will clear the concept.
Listing 3: Example of Logical Operator
Figure 3: Above figure is output of logical operator script which ask for entering the value between 100 and 500. If the value is right then it will print 'Entered number follows the conditions of these logical operations otherwise false.
Assignment operator allows you to assign values to variables always assigns a value to its left operand based on the value of its right operand. The first operand must be a variable and basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. Example: X=Y means value of Y is assigning in memory of X .listed example will show you how to work with assignment operator.
Listing 4: Example of Assignment Operator
Figure 4: Above figure is example of assignment operator script in which two different value is assigned to two separate variable.
The conditional operator is replacement of if statement. It takes three operands. Condition: An expression that evaluates to true or false. Expression A and Expression B: Expressions with values of any types. If condition is true, the operator returns the value of Expression A; otherwise, it returns the value of Expression B.
result = (age >= 24) ? "True" : "False"
The statement assigns value "True" to the variable result if age is 24 or more. Otherwise it assigns the value of "False" to result.
Listing 5: Example of Conditional Operator
Figure 5: Above figure is prompt box which asked for entering your age. It calculates that your entered age is less than or greater than 24. After comparing the values result obtained is printed false for this program.