News for hackers. Stuff that matters.
Re:JSFuck (2012) by idolaspecus on Sunday September 26, 2021 @12:02AM (#28658299)
This is in my opinion actually a decent interview question. If you know JS in detail, if you know how the "+" operator works, it's a super easy question. If you don't know JS in detail, if you don't know how the "+" operator works, it's pretty tough. If you want an engineer who knows JS in detail, asking this question can be valuable.
Re:JSFuck (2012) by colordrops on Sunday September 26, 2021 @03:03AM (#28658989)
"+" isn't some singular operator. They are different operators for different types using the same character. You'd have to memorize a table of all JS types and what "+" does for each, which is silly considering that the only place it should really be used in modern JS is arithmetic and the occasional string concatenation.
Re:JSFuck (2012) by dorgo on Sunday September 26, 2021 @06:13AM (#28659704)
afaik these two places ( arithmetic and string concatenation ) are the only ones where + operation is defined. JS picks one of these two operations and casts the operands accordingly.

Edit: Wait, there is also the unary + which takes only one argument, but it also could be considered arithmetic.

Re:JSFuck (2012) by Aeolun on Sunday September 26, 2021 @04:04AM (#28659210)
That may be relevant if you are working on a javascript engine, not if you build webapplications.
Re:JSFuck (2012) by afiori on Sunday September 26, 2021 @03:12AM (#28659023)
it would be more relevant to ask about the valueOf method that can mess up all the various conversions.