DEV Community

Cover image for Guess the JavaScript Output: Level impossible!
Sadeedpv🥇
Sadeedpv🥇

Posted on

Guess the JavaScript Output: Level impossible!

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)

Collapse
 
pengeszikra profile image
Peter Vivo •

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.

Collapse
 
sadeedpv profile image
Sadeedpv🥇 •

Wait! is this even possible in JavaScript? 🤔

Collapse
 
pengeszikra profile image
Peter Vivo •

yes it is possible, I am solved, but few others too.

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • • Edited

9. Took about a minute

Collapse
 
sadeedpv profile image
Sadeedpv🥇 •

Hey 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)

Collapse
 
jonrandy profile image
Jon Randy 🎖️ •

My Twitter is on my profile - you could send a DM there

Thread Thread
 
sadeedpv profile image
Sadeedpv🥇 •

I tried, but only verified users can send messages

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️ •

Ah ok. My GMail address shouldn't be too hard to work out

Thread Thread
 
sadeedpv profile image
Sadeedpv🥇 •

Feel free to share it if you're comfortable

Collapse
 
sadeedpv profile image
Sadeedpv🥇 •

You are a senior dev for a reason 😄

Collapse
 
vsaulis profile image
Vladas Saulis • • Edited

Three "NaN"s. Length = 9.

Collapse
 
sadeedpv profile image
Sadeedpv🥇 • • Edited

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

Collapse
 
mflorida profile image
Mark M. Florida •

I don't know because I'm not a computer!