r/badcode • • May 31 '21

js Clever?

Post image
2.2k Upvotes

71 comments sorted by

View all comments

242

u/HalcyonAlps May 31 '21

Now I am actually curious, does the compiler realize both branches have the same return value and it just drops the whole if-statement?

100

u/[deleted] May 31 '21

Depends on whether or not the compiler is smart enough to realize that evaluating the conditional has no side-effects. Not sure what language this is

73

u/givemeagoodun May 31 '21 edited Jun 01 '21

It's flaired JS so it's JS

72

u/[deleted] May 31 '21

In that case the answer is an easy "no" since it's not a compiled language and there's no compiler

0

u/[deleted] Jun 01 '21

FireFox's SpiderMonkey and Chrome's V8 are both JITs and optimize at runtime. They would probably catch it.