= is the same as = in any shell that supports ] (introduced by ksh). You need ] for byte-to-byte equality comparison.
There are three main types of operators: Numeric, Comparison and Logical operators.] is not comparison, it's pattern matching.
Operators are used to perform operations on values. There are six types and they are: number, string, boolean, function, object and undefined. Values are the data used by your program.Įvery value in Apps Script has a type. In this lesson, you learned about values, types and operators in Apps Script. Logger.log(typeof "%*&^*#^") //string Conclusion Logger.log(typeof "Hello world!") //string
DOES NOT EQUAL SIGN SCRIPT CODE
The code examples below demonstrate how this operator works. The typeof operator is used to find out the type of a given value. The above eligibility criteria can be implemented in the following way: Their parents' income must be less than or equal to $70K. In order to be eligible, a student must meet both of the following conditions: The school has the following policy for awarding these scholarships. Imagine that a school administrator wants to figure out which students are eligible for a scholarship. It is common for Comparison and Logical operators to be used together For example, !a results in true if a is false. NOT (!): false becomes true and vice versa. It results in false only if both a and b are both false. OR (||): a || b results in true if either one or both values are true. It results in false if either one or both of them are false. There are three logical operators and they are:ĪND (&): a & b results in true only if both a and b are both true. Logical operators operate on boolean values with the result also being a boolean value. To prevent Apps Script from converting types when comparing values, use the strict equality operator (=) or the strict inequality operator (!=). When you compare two values of different types, Apps Script converts them to the same type before comparing them. 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?