Aaron Martin-Colby is a user on mastodon.cloud. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Aaron Martin-Colby @amc

Pop quiz!: What will log to the console and why?

console.log(typeof + +"3");

@amc checked the output. Would like to know what's happening there :sweat_smile:

@rcmainak It's JavaScript being JavaScript. It's because JS treats each + as a unary operator, the first operates on the second, and they are both positive so nothing changes, while the second operates on the string which coerces a number. So by the magic of JS, you get the number 3.

@amc The typeof and unary plus operator have the same precedence but are right-to-left, hence the interpretation as
typeof ( + ( + "3"))