Learning JavaScript, Day 5 – Even More Operators
While I'm going to keep on happily learning JavaScript, from mid-May I'm also going to doing something else.
I have decided to get an MSc in Digital Transformation from the University of Hull.
It's part-time and it's all online, which is nice, and I'm hoping that it gives me the language and data analysis skills to keep saying "No, we're not bringing that in. Have you seen how sketchy it is?"
Because, good lord, am I tired of seeing AI shoved everywhere it does not need to be.
I'll probably blog post my notes on the coursework, much like I'm doing here, but since it involves reading stuff with titles like "IT-Enabled Business Transformation: From Automation to Business Scope Redefinition" and, god help me, Satoshi Nakamoto's original Bitcoin paper, it's not going to be as fun, and will probably have me regularly going "Oh my god, people actually bought into this?"
...
At least my new couch is very comfy. And I have JavaScript Operators to look at.
JavaScript Arithmetic Operators
I do like how I get the fancy names for things, like "Operators" and "Operands".
I mean, I don't think I'll ever actually use them, but knowing is half the battle.
It doesn't explain the difference between "arithmetic" and "mathematics", which comes up in this notice:
In arithmetic, the division of two integers produces a quotient and a remainder.
In mathematics, the result of a modulo operation is the remainder of an arithmetic division.
But I think that's way out of the remit of a JavaScript course, isn't it?
I also learn about Math.pow() which is just doing exponents, but it is also cracking me up because POW. POW POW TAKE THAT MATH.
The course then briefly mentions BEMDAS, but keeps it fairly light, which helps immensely and I don't end up snapping again.
Alas, the exercise is all maths, and I am so tired oh my god don't make me try to think of how math works.
But guess what? I was asked what 100 + 50 * 3 would be, and I remembered my BEMDAS and I got it right.
Gold star for me!
JavaScript Assignment
Assignment operators are pretty straightforward, and it goes into them quite nicely.
= assigns a value to a variable. Yep.
+= adds a value to a variable, -= takes away a value, *= multiples the variable, /= divides the variable, **= raises the variable to the power of a value, and %= gives you the remainder of the variable. Which is all maths-related yep.
And you can use += with strings as well. Yep.
There's one that they show in the big list but they left off in the explanations in the maths ones.
x:45 is the same as size.x = 45 which gives you a result of x = 45. What does this all mean?
I guess I'll find out later, because then we move to logical operators, which I need to pay a little more attention to, because these are pretty different and new to me.
&&= is the Logical AND assignment operator. It's used between two values and it says that if the first value is true, then the second value is assigned.
So, like,
let largeBoi = true;
let thisBoi = largeBoi &&= "moose";
document.getElementById("demo").innerHTML =
"This boi is a " + thisBoi;
Gets me:
This boi is a moose
But when I set largeBoi to false, I get This boi is a false. Which is fair. When I get into if statements I can do all sorts of hijinx.
And then there's ||= which is Logical OR assignment operator. Which is the opposite of &&=, so if I have:
let largeBoi = true;
let thisBoi = largeBoi ||= "moose";
document.getElementById("demo").innerHTML =
"This boi is a " + thisBoi;
I get:
This boi is a true
??= has the most awkward proper name. "Nullish coalescing assignment operator", which is a lot of words for "apply this when the other variable doesn't have anything in it."
Which I can see coming in really handy when your variable has a user-inputted value. Like...
let weatherC;
weatherC ??= "undefined temperature.";
document.getElementById("demo").innerHTML =
"The weather is " + weatherC;
Which would give me:
The weather is undefined temperature
Then it has a quick reference that is cracking me up.
x &&= y: assignsytoxonly ifxis truthy
x ||= y: assignsytoxonly ifxis falsy
"Truthy"? "Falsy"? You expect me to say "falsy" with a straight face?
It doesn't help that the next bit is labeled
The 8 FALSY values
These are important and I cannot stop laughing.
It points out that if you have something like "false", that's actually a true value, because it's in a string, and it doesn't matter what you actually put in a string.
And, finally, ... is the spread operator, that breaks things into their individual elements.
It shows it in a maths setting, where you can get the minimum and maximum of a string of numbers, but I'm not 100% certain what else you would use it for, nor do I know exactly what you would do with it in this instance. Because, like,
let text = "12345";
let min = Math.min(...text);
let max = Math.max(...text);
Okay, yeah, that does return me 1 and 5. And if I reverse the number to be "54321", it gives me the same results, because 1 is still the minimum, 5 is still the maximum, but, like, what else can I do with it?
Maybe I'll see how it can be used later.
Day 5 — Results
- Operands are the things that are being operated on.
- Operators are the things that make the operation happen.
**does the same asMath.pow(), which are exponents of numbers.&&=does "apply this value to this variable when the other variable is true"||=does "apply this value to this variable when the other variable is false"??=does "apply this value to this variable when the variable doesn't have a value"- Things that are false:
false,0,-0,0n, empty strings,null,undefined, andNaN. - Things that are true:
"0","false", empty arrays, and empty objects. ...is the spread operator, that breaks up a value into its individual elements.
I'm going to stop there, because, dang, operators are surprisingly heavy on the brain usage. Even when I'm just doing nonsense like "a moose is a large boi".
Today's Sticker

Shifty Thrifting's Vaporwave Moose. For he is a large boi. So very large.
Although this just reminds me that I want to buy a billion more Vaporwave Coelacanth Stickers so that I have coelacanths everywhere in my house.
More so.
(I have a lot of coelacanths, okay? They're my favourites.)