You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Almost all mathematical operations convert values to numbers. A notable exception is addition `+`. If one of the added values is a string, the other one is also converted to a string.
86
-
87
-
Then, it concatenates (joins) them:
88
-
89
-
```js run
90
-
alert( 1 + '2' ); // '12' (string to the right)
91
-
alert( '1' + 2 ); // '12' (string to the left)
92
-
```
93
-
94
-
This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.
95
-
````
84
+
Most mathematical operators also perform such conversion, we'll see that in the next chapter.
: The object and its property to apply the descriptor.
67
67
68
68
`descriptor`
69
-
: Property descriptor to apply.
69
+
: Property descriptor object to apply.
70
70
71
71
If the property exists, `defineProperty` updates its flags. Otherwise, it creates the property with the given value and flags; in that case, if a flag is not supplied, it is assumed `false`.
1. Get all `<tr>`, like `table.querySelectorAll('tr')`, then make an array from them, cause we need array methods.
13
-
2. The first TR (`table.rows[0]`) is actually a table header, so we take the rest by `.slice(1)`.
14
-
3. Then sort them comparing by the content of the first `<td>` (the name field).
15
-
4. Now insert nodes in the right order by `.append(...sortedRows)`.
11
+
The step-by-step algorthm:
16
12
17
-
Tables always have an implicit `<tbody>` element, so we need to take it and insert into it: a simple `table.append(...)` would fail.
13
+
1. Get all `<tr>`, from `<tbody>`.
14
+
2. Then sort them comparing by the content of the first `<td>` (the name field).
15
+
3. Now insert nodes in the right order by `.append(...sortedRows)`.
18
16
19
-
Please note: we don't have to remove them, just "re-insert", they leave the old place automatically.
17
+
Please note: we don't have to remove row elements, just "re-insert", they leave the old place automatically.
18
+
19
+
Also note: even if the table HTML doesn't have `<tbody>`, the DOM structure always has it. So we must insert elements as `table.tBodes[0].append(...)`: a simple `table.append(...)` would fail.
Copy file name to clipboardExpand all lines: 2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/solution.view/index.html
0 commit comments