r/ProgrammerHumor • • Mar 20 '24

Meme areJSDevsActuallySane

Post image
14k Upvotes

554 comments sorted by

View all comments

Show parent comment

4

u/[deleted] Mar 21 '24

lmao

I just assumed it ran the code. Going back to the conversation, here is what it decided to run.

# JavaScript expression explained in the query:
# (![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]

# Equivalent Python code to mimic the JavaScript type coercion and operations
# Explanation based on the JavaScript coercion rules:
# - `![]` is false, but when used in string context, it becomes "false"
# - `+[]` is treated as 0
# - `+!+[]` is true coerced to 1
# - `!+[]+!+[]` is 1 + 1 = 2

# Constructing the string based on the operations
part1 = "false"[0]  # f
part2 = "false"[1]  # a
part3 = "falseundefined"[2]  # l
part4 = "false"[2]  # l

# Combine parts
result = (part1 + part2 + part3 + part4).upper()  # To uppercase as in the original joke

result

It was really dumb at being smart