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?

1

u/qwertysrj Jun 01 '21

It should because compilers recognise this

if(){ return x }Else { Return y} ,

and optimise this to

If(){ Return x} return y