Transcript from the "Operators" Lesson
[00:00:37] We've already seen a couple, these two bullet points, each have an operator in them. So in string " ALOHA" + "!", what's the operator, do you think?
>> The plus. Excellent, because ALOHA a string, the exclamation point is also a string, the plus is the only thing left, the plus is the operator.
[00:01:04] And then in type of value, in this case a string value, the operator is?
[00:01:34] I've been calling these things like magical spells, but they have more technical terms than that, and there are things of different types. So in this case, type of the kind of thing that it is, the kind of spell that it is, it's an operator. It's an operator that operates on a value, so you put it right before a value and then it tells you the string name of that value's type.
[00:01:58] So type of sting value, we'll say string. The plus operator in "ALOHA" + " !", we said it does what? What does that operator do? Concatenates.
>> Steven, here you said?
>> You said it already.
>> Could you say it?
>> Concatenates, yes. So Steven and OJ both say concatenates the two strings.
[00:02:41] We already saw that what it does when operating on strings, OJ just said concatenates the two strings. Any other guesses on the kinds of things you could use the plus operator with? We already looked at one, Bob, so what other types of values could a plus operator operate on?
>> Numbers, plus we can use it to do what two numbers? Add them exactly. So here's the question, how many values does the plus operator need to do its job, whether strings or numbers? Especially for adding, right, two numbers, you can't just add one number, you have to have another number to add it to.
[00:03:27] So it needs two values to do its job when it's adding numbers or when it's concatenating strings. Now it actually does have other things that can do that regard different numbers of values but we're just gonna kind of gloss over that because it's what is often called an overloaded operator.
[00:03:44] So it's an operator that does multiple different functions depending on how you're using it and what you're using it with. There are some other arithmetic operators that you might have seen, or if not, we're looking at now. So plus is for add, the minus sign, subtract. The star is like, what in elementary school maybe you used an X for, but also in math can sometimes be a dot or a star, different things.
>> Something else.
>> Something else is our guess. Let's find out, shall we? We can try, I'm just gonna copy this and go back in here. Okay, let's make this a little bit simpler. Let's cut out some of this. So if I have 4 + 1 * 2, I get 6.
[00:05:52] So what does it seem to be doing?
>> Respecting the order of operations.
>> That's respecting an order of operations where multiplication happened before addition, same as in math class. So these operators, they take the same precedence as you might expect in math class. Now, what happens if I want the addition to happen first?