This post is part of a series called Guess the JavaScript Output
If you like to read Part 1 of the series, see here
So, without any ado, let's get to it:
Today's question(Super tricky):
What does console.log((! + [] + [] + ![]).length)
output in JavaScript?
Big Mike solved this in 2 minutes. Can you beat big Mike on this one? Even ChatGPT got this one wrong!!
And Yes, JavaScript is officially crazy!
Top comments (13)
try this: codewars.com/kata/59a421985eb5d4bb...
You need to write a function f that returns the string Hello, world!.
Requirement: Every line must have at most 1 character, and total number of lines must be less than 145.
Hint: It's possible to complete this in less than 99 (tsukumo) lines.
Wait! is this even possible in JavaScript? 🤔
yes it is possible, I am solved, but few others too.
9
. Took about a minuteHey Jon, I have been following you on this platform for some time now and I know you've been coding for years. I've reached a stage in my career where I could use some advice. Is there anyway we could get in touch? (I know this is completely unrelated, but I would really appreciate a response here)
My Twitter is on my profile - you could send a DM there
I tried, but only verified users can send messages
Ah ok. My GMail address shouldn't be too hard to work out
Feel free to share it if you're comfortable
You are a senior dev for a reason 😄
I don't know because I'm not a computer!
Three "NaN"s. Length = 9.
You guessed the output, but the reasoning is wrong.
So, let me explain:
First ! + [] negates to true (+[] will result in 0),
Then we got "![]" ([] ==> true but ![] == false)
so "truefalse".length will give us 9