Skip to content

Comment on JS performance: try / catch versus checking for undefined parent

Comments

That's true - how about repeating the test with valid code that DOESN'T throw an exception.

- Edit -

Just tried it, it's not even close (on FF4):

tryCatch with undef - ~55,000

ifCheck with undef - ~2,000,000

tryCatch with Object - ~100,000,000

ifCheck with Object - ~2,000,000

So if an error is not thrown the try/catch expression is WAY faster.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.