![]() ![]() ![]() Comparison operators do not change the value of the variable. Notice that if you type greeting after this, you will see that the variable greeting still contains the string hello world. They simply represent being true or false.Ĭomparison operators work for strings as well. true and false aren't strings - they're called booleans. Notice that there are no quotes around these values. You should have seen that the comparison operators return one of two values: true or false. It does things like return true for "2" = 2, but many of its rules are confusing, inconsistent, and hard to remember. JavaScript also has an operator with 2 equal signs, but it is almost never used, and you should generally avoid it. Mixing these up is one of the easiest syntax errors to make. When we're setting a variable equal to something, we use = (single equal sign). When we're asking whether something is equal, we use = (3 equal signs). Comparison operators do not change any values, but return true or false depending on whether the statement evaluates as true or false. Let's do one of each: > let testNumber = 10 Īssignment operators change the value of the variable on the left of the operator. When you use any of these assignment operators, the value of the variable on the left side is changed by the math operation and value on the right. There is an assignment operator for each of the mathematical functions: addition, subtraction, multiplication and division. In the above example, favoriteNumber is assigned the value 42.Īnother assignment operator is the += operator, because it too assigns a new value to the variable on the left based on the value to the right. The = is called an assignment operator because it assigns the value on the right of the operator to the variable on the left. We've already seen how we can use the = operator to set a variable equal to a value. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |