Assume that we have the following snippet of JavaScript code:

```
<script>
var result = (2..valueOf() + ({z : 10, x : 20}).x);
alert(result);
</script>
```

__Question__: Will this code succeed or fail? And if it succeeds, what is the output of the alert?

**Write your answer on a piece of paper and then read the answer.**

__Answer__:

The code will work fine. The final result is 22. Let’s understand why we will get this result. Let’s divide the expression in two parts. In the first part, we have:

`2..valueOf()`

This expression will work fine because in JavaScript, it is valid to trail decimal points in float numbers, that means 2, for example, can be represented as 2 or 2.0 or 2. (without having to mention the extra 0 after the decimal dot).

So the expression can be read simply as (2.).valueOf() which will return 2.

The second part is straightforward:

`({z : 10, x : 20}).x`

We have a JavaScript object with two attributes x and z, and we are getting the value of x using `.x`

, which means that the result will be equal to the value of `x`

, which is 20.

Adding the first part's result to the second part result will result in: 20 + 2 = 22.

## {{ parent.title || parent.header.title}}

## {{ parent.tldr }}

## {{ parent.linkDescription }}

{{ parent.urlSource.name }}