Skip to content

Commit

Permalink
feat: Add double dot example. Close #124
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdovhan committed Feb 6, 2021
1 parent f6cbab4 commit 597b5ee
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ Currently, there are these translations of **wtfjs**:
- [resolve() won't return Promise instance](#resolve-wont-return-promise-instance)
- [`{}{}` is undefined](#-is-undefined)
- [`min` is greater than `max`](#min-is-greater-than-max)
- [`agruments` 2-way binding](#agruments-2-way-binding)
- [`agruments` binding](#agruments-binding)
- [An `alert` from hell](#an-alert-from-hell)
- [An infinite timeout](#an-infinite-timeout)
- [Double dot](#double-dot)
- [πŸ“š Other resources](#-other-resources)
- [πŸŽ“ License](#-license)

Expand Down Expand Up @@ -1819,7 +1820,7 @@ The opposite is happening for `Math.min`. `Math.min` returns ∞, if no argument
- [**15.8.2.11** Math.min](https://262.ecma-international.org/5.1/#sec-15.8.2.12)
- [Why is `Math.max()` less than `Math.min()`?](https://charlieharvey.org.uk/page/why_math_max_is_less_than_math_min)

## `agruments` 2-way binding
## `agruments` binding

Consider this function:

Expand Down Expand Up @@ -1884,6 +1885,41 @@ Timeout duration was set to 1.
- [Node.js Documentation on Timers](https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args)
- [Timers](https://www.w3.org/TR/2011/WD-html5-20110525/timers.html) on W3C

## Double dot

Let's try to coerce a number to a string:

```js
27.toString() // > Uncaught SyntaxError: Invalid or unexpected token
```

Maybe we should try with a two dots?

```js
27..toString() // -> '27'
```

But why doesn't first example work?

### πŸ’‘ Explanation:

It's just a language grammar limitation.

The `.` character presents an ambiguity. It can be understood to be the member operator, or a decimal, depending on its placement.

The specification's interpretation of the `.` character in that particular position is that it will be a decimal. This is defined by the numeric literal syntax of ECMAScript.

You must always use parenthesis or an addition dot to make such expression valid.

```js
(27).toString() // -> '27'
// or
27..toString() // -> '27'
```

- [Usage of toString in JavaScript](https://stackoverflow.com/questions/6853865/usage-of-tostring-in-javascript/6853910#6853910) on StackOverflow
- [Why does 10..toString() work, but 10.toString() does not?](https://stackoverflow.com/questions/13149282/why-does-10-tostring-work-but-10-tostring-does-not/13149301#13149301)

# πŸ“š Other resources

- [wtfjs.com](http://wtfjs.com/) β€” a collection of those very special irregularities, inconsistencies and just plain painfully unintuitive moments for the language of the web.
Expand Down

0 comments on commit 597b5ee

Please sign in to comment.