Skip to content

shell.js: use === and !== where appropriate - #18746

Closed
wydengyre wants to merge 1 commit into
emscripten-core:mainfrom
wydengyre:shell.js-equal-value-and-type
Closed

wydengyre wants to merge 1 commit into
emscripten-core:mainfrom
wydengyre:shell.js-equal-value-and-type

Conversation

@wydengyre

Copy link
Copy Markdown

Usage of triple vs. double equalities in shell.js was inconsistent. In all cases where == and != were used in the file, === and !== are more appropriate.

At a minimum, the non-coercive equality checks show intention more clearly. They also are generally faster, though this is unlikely to matter in shell.js.

Usage of triple vs. double equalities in shell.js was inconsistent. In all cases where `==` and `!=` were used in the file, `===` and `!==` are more appropriate.

At a minimum, the non-coercive equality checks show intention more clearly. They also are generally faster, though this is unlikely to matter in shell.js.
@sbc100

sbc100 commented Feb 14, 2023

Copy link
Copy Markdown
Collaborator

As unusual as it sounds we actually deliberately use ==/!= when comparing typeof to a string constant. See #16261 for the rationale.

Sorry, I know if its kind of gross and goes against JS best practices, but we this code is included with every emscripten program, so if we can save even a couple of bytes here we do.

@sbc100

sbc100 commented Feb 14, 2023

Copy link
Copy Markdown
Collaborator

If we were to change our policy here we should also so it across the entire codebase, and not just in shell.js.

@wydengyre

Copy link
Copy Markdown
Author

@sbc100 Understood. Feel free to close this PR. This might be worth a wider discussion, but certainly it's not too important.

@sbc100 sbc100 closed this Feb 14, 2023
@wydengyre
wydengyre deleted the shell.js-equal-value-and-type branch February 14, 2023 17:46
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.

2 participants