question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: Prefer `Number` methods

See original GitHub issue

Fail

parseInt(…);
parseFloat(…);
isNaN(…);
isFinite(…);

Pass

Number.parseInt(…);
Number.parseFloat(…);
Number.isNaN(…);
Number.isFinite(…);

This rule cannot be auto-fixable as the globals methods have slightly different behavior. However, it should use the ESLint suggestions API.

Should we also enforce Number.NaN over NaN? They equivalent. I’m leaning towards “yes”, for consistency, and also less use of floating globals.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
jimmywartingcommented, Jun 18, 2021

I would like to see a reasoning for why number properties are better, (and not just because of global-phobia) If you can’t argument for a good reason, then don’t break something that isn’t broken.

I came here for the Number.NaN reason… never seen anyone write that …or using Number Number.NEGATIVE_INFINITY That’s just too long and unpleasant to write Some functions are the same, parseInt === Number.parseInt, Number.parseFloat === parseFloat, So why should you use Number[xxx]?

isNaN i can understand it’s not the same as Number.isNaN and dose things differently

The global isNaN() function converts the tested value to a Number, then tests it.

There may just be usecases where you would prefer to use one over the other, just because of it’s differences

1reaction
fiskercommented, Mar 19, 2022

I think

- if (isNaN(numberOrIdk)) {
+ if (Number.isNaN(Number(numberOrIdk))) {

is more correct.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposed Rule: Further Definition of “As a Part of a Regular ...
4 Accordingly, the Commission is proposing to further define what it means to be buying and selling securities “as a part of a...
Read more >
A Guide to the Rulemaking Process - Federal Register
Before the Proposed Rule. What gives agencies the authority to issue regulations? How does an agency decide to begin rulemaking?
Read more >
Medicare Program: Payment Policies under the Physician Fee ...
Summary. This major proposed rule addresses changes to the physician fee schedule and other Medicare Part B payment policies, such as changes to...
Read more >
17 CFR § 240.14a-8 - Shareholder proposals. - Law.Cornell.Edu
(2) One of the following methods must be used to demonstrate your eligibility to submit a proposal: (i) If you are the registered...
Read more >
Outline for Research Proposal - Portland State University
Outline for Research Project Proposal · 1. Introduction · 2. Background/Review of the Literature · 3. Rationale · 4. Method and Design ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found