js trivia challenge!
you can write anything on line one, how are you getting the flag?

i originally wanted to make this into a ctf chall, but it's a bit too "win by knowing 1 obscure trick" to be good

@rebane2001 oh wow, that was harder than I thought.

Final answer: const x = (BigInt.prototype.length = 1, 0n)

What I tried:

  • Realize you need a value that's falsy but has a truthy length.
  • Try to use an object with [Symbol.toPrimitive] custom implementation. Failed because objects are directly truthy and not converted to bool.
  • Try to override String.prototype.length and use an empty string. Failed because init x as an empty string seems to set the length again.
  • Had to look up falsy JS values and saw BigInt. Good because 0n is falsy, and BigInt doesn't use length so we can set it without it getting reset.

Phew, it was a lot harder than I thought at first. But then, if you know the solution it's not that hard to understand.

@miro @rebane2001 you can also do this with Boolean.prototype.length = 1, false