# JavaScript Quiz #8 (One Line Quiz)

# JavaScript Quiz #8 (One Line Quiz)

### This week's JavaScript Quiz just a one-liner. See if you can tell if this code will succeed or fail, and learn about using decimal points in float numbers.

Join the DZone community and get the full member experience.

Join For FreeLearn how Crafter’s Git-based content management system is reinventing modern digital experiences.

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.

Crafter CMS is a modern Git-based platform for building innovative websites and content-rich digital experiences. Download this white paper now.

Published at DZone with permission of Hazem Saleh , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

## {{ parent.tldr }}

## {{ parent.linkDescription }}

{{ parent.urlSource.name }}