Preact: Force consistent use of double or triple equal/not equal in typeofs

Created on 15 Nov 2019  路  13Comments  路  Source: preactjs/preact

Reading through the source code, I find places where == or != are used for typeof, and others where === or !== are used. I believe we should choose one and stick with it. I'd be happy to open a PR for this once there is agreement on which choice should be used.

Note: looking at the produced bundles, it seems that with typeof, === is compiled to ==, and !== is compiled to !=. So, there shouldn't really be any differences in performance and bundle size.

beginner-friendly

Most helpful comment

I personally have no feelings about this topic but as the minifier will convert them to ==/!= I'd use that notion directly in the code.

All 13 comments

Sounds like an easy we to get some nice contribution stats :+1: If it indeed does not affect bundle size I'm all for it :+1:

I think it shouldn't matter since there are that many = that gzip makes it a noop

You're right. Since the bundle size won't change, I think we should be consistent and stick with one. Additionally, as I stated above, triple equals are compiled down to double equals anyway.

I'd like to open a PR for this one. However, before I do, should I use === and !== or == and !=?
If you want, I can leave it for new contributors since it's labeled beginner-friendly.

I personally have no feelings about this topic but as the minifier will convert them to ==/!= I'd use that notion directly in the code.

Hey everyone,
this is my first time to contribute code to an oss project. As I read in many articles I should look out for issue tags like "good first". So here I am. But I question me, is the described issue here even open, because of the last linked PR from mhmdanas ? It seems to me that only the build pipeline is failed or ?

Welcome @friebe
Nothing wrong with the build pipeline, that PR has a merge conflict that needs to be resolved that's why it's indicating as impossible to merge.

Since my PR for this issue has been closed, should we close this issue? I think this could be considered a stylistic choice, just like choosing between const and let. And they're all compiled to double equal anyway.

@mhmdanas I'm happy to accept any PRs for this. I just closed yours because it has had merge conflicts for about a month now, so I thought it can be closed. In either way you're right on the money in that it is more of a stylistic choice.

Ah ok thanks. Keeping this issue up then.

Note I know of at least one place where !== is explicitly used to check against undefined. It's commented in code so just keep an eye out for things like this.

@andrewiggins I think you misunderstood this issue. The aim here is to change comparisons with typeof only.

Oh that's right, thanks for pointer :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kay-is picture kay-is  路  3Comments

mizchi picture mizchi  路  3Comments

jescalan picture jescalan  路  3Comments

matuscongrady picture matuscongrady  路  3Comments

skaraman picture skaraman  路  3Comments