Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change typeof <v> !== 'undefined' to <v> !== void 0 #2960

Closed
wants to merge 1 commit into from
Closed

change typeof <v> !== 'undefined' to <v> !== void 0 #2960

wants to merge 1 commit into from

Conversation

mikrofusion
Copy link

This request is to modify the places in the code where "typeof !== 'undefined'" to " !== void 0" where is a variable (in this case exports and window).

A few reasons for the request:

  1. I have seen performance improvements by going with the void 0 approach. Supporting data: http://jsperf.com/typeof-vs-undefined-check/15
  2. It reduces the overall number of characters used to test whether the variable is undefined (an overall bandwidth improvement).
  3. Although 1 & 2 are negligible for this project due to only being used in a few places, this seems to be a best practice being used by other libraries (i.e. underscore.js) and would be good to use for continuity of best practices between projects.

Thanks!

@braddunbar
Copy link
Collaborator

Hi @mikegroseclose! While Backbone and Underscore do use void 0 in place of undefined as a matter of style, this code is comparing the type to 'undefined' (note the quotes) in order to avoid throwing when it's not in scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants