Hey, meme!
What happens in JavaScript if we type a variable whose value is “b”+”a”+ + “a” + “a”+ “!”.toUpperCase()?
Let’s write the code and see!
First we take a variable and give it the specified value.
let meme = (“b” + “a” + + “a” + “a”+ “!”).toUpperCase();
console.log(meme);
Now let’s think!
We see four operators + . One of them is unary (+ “a”) (if you haven’t guessed yet, it’s the third + ) (because we have + +”a” )
Get Medium Profile’s stories in your inbox
Join Medium for free to get updates from this writer.
Who gets executed first? The unary operator, because it’s more important than the binary operators. + “a” returns NaN
Now we have “b”+ “a” + NaN + “a” + “!”
The first binary operator + concatenates character b and character a . Thus, we have “ba” + NaN + “a” + “!”
Now JS tries to convert NaN to string so we have “baNaN” + “a” + “ !”
We actually have two operators +
So first we obtain “baNaNa” + “!”
then we have “baNaNa!”
The toUpperCase function is used to transform all the characters of a string into uppercases
So, we finally have “BANANA!”
The output will be “BANANA!”





