Commit f1f38532 authored by Scott Stern's avatar Scott Stern Committed by Paul Slaughter

Change strictness of parseInt rule

Provide clarity for using parseInt vs Number
in string to num conversions.

See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/22721
parent 9e84a03c
...@@ -98,16 +98,27 @@ class a { ...@@ -98,16 +98,27 @@ class a {
} }
``` ```
## Use ParseInt ## Converting Strings to Integers
Use `ParseInt` when converting a numeric string into a number. When converting strings to integers, `parseInt` has a slight performance advantage over `Number`, but `Number` is semantic and can be more readable. Prefer `parseInt`, but do not discourage `Number` if it significantly helps readability.
**WARNING:** `parseInt` **must** include the [radix argument](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt).
```javascript ```javascript
// bad // bad
Number('10') parseInt('10');
// bad
things.map(parseInt)
// ok
Number("106")
// good
things.map(Number)
// good // good
parseInt('10', 10); parseInt("106", 10)
``` ```
## CSS Selectors - Use `js-` prefix ## CSS Selectors - Use `js-` prefix
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment