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.md22
1 files changed, 13 insertions, 9 deletions
diff --git a/doc/development/fe_guide/style/javascript.md b/doc/development/fe_guide/style/javascript.md
index d04d1879476..d93dc8292d4 100644
--- a/doc/development/fe_guide/style/javascript.md
+++ b/doc/development/fe_guide/style/javascript.md
@@ -100,27 +100,31 @@ class a {
## Converting Strings to Integers
-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.
+When converting strings to integers, `Number` is semantic and can be more readable. Both are allowable, but `Number` has a slight maintainability advantage.
**WARNING:** `parseInt` **must** include the [radix argument](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt).
```javascript
-// bad
+// bad (missing radix argument)
parseInt('10');
-// bad
-things.map(parseInt)
-
-// ok
-Number("106")
+// good
+parseInt("106", 10);
// good
-things.map(Number)
+Number("106");
+```
+
+```javascript
+// bad (missing radix argument)
+things.map(parseInt);
// good
-parseInt("106", 10)
+things.map(Number);
```
+**PLEASE NOTE:** If the String could represent a non-integer (i.e., it includes a decimal), **do not** use `parseInt`. Consider `Number` or `parseFloat` instead.
+
## CSS Selectors - Use `js-` prefix
If a CSS class is only being used in JavaScript as a reference to the element, prefix