4 ms·
To clarify I wasn't being hypothetical, I think v8 will optimize out that check today. I phrased it vaguely because I'm not sure whether other engines would as
by fenomas 8y ago
To clarify I wasn't being hypothetical, I think v8 will optimize out that check today. I phrased it vaguely because I'm not sure whether other engines would as well.
- braythwayt 8y agoIt’s certainly doable. The `defaultValue` parameter is passed by value, so it will never be rebound. The result of using `typeof` on a value never changes in JS, even if the value is modified. So... it should be possible to optimize the check away after the first time.