Free JavaScript Editor DHTML Editor

↑

Main Page |

## 2.3 Testing Numeric EqualityNN 2, IE 3 ## 2.3.1 ProblemYou want to know whether two numeric values are equal (or not equal) before continuing processing. ## 2.3.2 SolutionUse the standard equality operator ( if (firstNum = = secondNum) { // OK, the number values are equal } Values on either side of the equality operator may be variables or numeric literals. Typical practice places the suspect value to the left of the operator, and the fixed comparison on the right. ## 2.3.3 DiscussionJavaScript has two types of equality operators. The fully
backward-compatible, standard equality operator ( var numA = 45; var numB = new Number(45); These two variables might contain the same numeric value, but they
are different data types. The first is a number value, while the
second is an instance of a numA = = numB returns But the other type of equality operator, the strict equality operator
( numA = == numB If one equality operand is an integer and the other is the same integer expressed as a floating-point number (such as 4 and 4.00), both kinds of equality operators find their values and data types to be equal. A number is a number in JavaScript. If the logic of your code requires you to test for the inequality of
two numbers, you can use the inequality ( if (parseInt(document.myForm.myTextBox.value) != 0) { // process entry for non-zero values } The same issues about data type conversion apply to the inequality and strict inequality operators as to their opposite partners. ## 2.3.4 See AlsoRecipe 2.1 for converting between number and string value types. |

Main Page |

→ online casino canada

JavaScript Checker DHTML Editor

©