Skip to content
Advertisement

What’s the performance difference between “skip if condition” and “directly return”?

Is there any performance difference between the following 2 functions:

JavaScript

Which one has a smaller execution time?

Advertisement

Answer

I don’t think there is a performance difference, but the second function is better for readability, because you don’t have to indent. Also you can use !a in the if statement in the second function for better readability.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement