

How can a number be equal to text? This is due to automatic type conversion.

When you compare the number 1 with the text "1" using the equals (=) operator, the result is true. To understand the difference, you need to understand a concept called type conversion. What is the difference between = and = OR between != and !=? Strict inequality (!=): a != b results in true if the value a is not equal to value b OR if their types are different. Inequality (!=): a != b results in true if both values are of the same type but value a is not equal to value b. Strict equality (=): a = b results in true if the value a is equal to value b and their types are also the same. Less than or equal to (<=): a <= b results in true if the value a is lesser than or equal to value b and false if a is greater than b.Įquality (=): a = b results in true if the value a is equal to value b. Less than (<): a < b results in true if the value a is lesser than value b and false if a is greater than or equal to b. Greater than or equal to (>=): a >= b results in true if the value a is greater than or equal to value b and false if a is less than b. Greater than (>): a > b results in true if the value a is greater than value b and false if a is less than or equal to b. For example, 5 > 1 results in true but 1 > 20 will result in false. When you compare two values the result is either true or false, i.e., a boolean value. For example, the > (greater than) operator is used to check if a value is greater than another value. Comparison operatorsĬomparison operators are used to compare two values. Insead of learning all of the operator precedence rules in Apps Script, just use parentheses in situations like this to ensure Apps Script does whatever it is that you want it to do. (2 + 2) * 4: The addition will happen first followed by the multiplication. The expression within the parentheses will be evaluated first.Ģ + (2 * 4): The multiplication will happen first followed by the addition. You can force Apps Script perform a certain operation first by using parentheses (round brackets). These rules are called operator precedence rules. This is because Apps Script has rules for what to do in situations like this. There is only one correct answer and that is 10. If you do the multiplication first, you get 2 + 8 which is 10. It depends on which operation occurs first, doesn't it? If you do the addition first you get 4 * 4 which is 16. What is the value that gets logged when you execute the following code?
