Sitemap
Medium Profile

Medium Profile

I am a web developer and teacher

Hey, meme!

1 min readAug 12, 2023
Press enter or click to view image in full size
banana

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!”

--

--

Medium Profile
Medium Profile

Written by Medium Profile

0 followers

I am a web developer and teacher