Question: Can anybody explain me why this javascript code alerts "47" ?

```
var component = +((!+[] + !![] + !![] + !![] + []) + (!+[] + !![] + !![] + !![] + !![] + !![] + !![]));
alert(component);

```

how those brackets, plus signs, etc return 47 at the end when I execute them ?

how to write this in PHP. I understand this is something with strings, booleans, etc.. but can't understand it ?

Answer: 
In JavaScript, `false + false -> 0`, `false + true -> 1`, `true + true -> 2`. The arrays are not used directly, except to be a source expression: `![] -> false`, `!![] -> true`, `!+[] -> true`, and `number + [] -> "number"`.

Thus we have (where t = true, f = false):

```
+((!+[] + !![] + !![] + !![] + []) + (!+[] + !![] + !![] + !![] + !![] + !![] + !![]));

+((t + t + t + t + []) + (t + t + t + t + t + t + t));

+((4 + []) + (7));

```

Now, see `4 + []`? That is handled as a string *concatenation* after conversions, and the result is "4" so:

```
+(("4") + (7))

+("4" + 7)

+("47")

47

```

I have no idea how this particular piece would translate to PHP.
```
+[] -> 0 //Because + converts all other javascript types to numbers
!+[] -> true //Because ! converts 0 to true
![] -> false //Empty array is true 
!![] -> true //Because ![] is false

```

`(!+[] + !![] + !![] + !![] + []) -> true+true+true+true+""="4"`

`+` converts **Boolean** value to **1** if it is `true`, and **0** if it is `false`.` 

And **this is a string value**,because `Number`+`Empty object` creates a **string**, because an **Empty Object** can't convert to `Number` it converts to a `String`. And as we know `Number+String->String`. 

**As a result:** `(!+[] + !![] + !![] + !![] + [])` **is the same as** `"4"`

In the same way

```
(!+[] + !![] + !![] + !![] + !![] + !![] + !![]) -> true+true+true+true+true+true+true = 7 //this is a Number, because Boolean value converts to a Number: either 0 or 1    

```

And finally 

```
"4"+7=47

```