Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/development/fe_guide/style/javascript.md')
-rw-r--r--doc/development/fe_guide/style/javascript.md21
1 files changed, 16 insertions, 5 deletions
diff --git a/doc/development/fe_guide/style/javascript.md b/doc/development/fe_guide/style/javascript.md
index 334372af1f4..a2035eb1b55 100644
--- a/doc/development/fe_guide/style/javascript.md
+++ b/doc/development/fe_guide/style/javascript.md
@@ -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
// bad
-Number('10')
+parseInt('10');
+
+// bad
+things.map(parseInt)
+
+// ok
+Number("106")
+
+// good
+things.map(Number)
// good
-parseInt('10', 10);
+parseInt("106", 10)
```
## CSS Selectors - Use `js-` prefix
@@ -297,7 +308,7 @@ Strive to write many small pure functions and minimize where mutations occur
## Export constants as primitives
-Prefer exporting constant primitives with a common namespace over exporting objects. This allows for better compile-time reference checks and helps to avoid accidential `undefined`s at runtime. In addition, it helps in reducing bundle sizes.
+Prefer exporting constant primitives with a common namespace over exporting objects. This allows for better compile-time reference checks and helps to avoid accidental `undefined`s at runtime. In addition, it helps in reducing bundle sizes.
Only export the constants as a collection (array, or object) when there is a need to iterate over them, for instance, for a prop validator.