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: 
There is various things need to analysis one by one, let's start: 

suppose

```
var p = [];
console.log(typeof p) // => object (array) 
console.log(p) //=> []

```

Again, 

```
var p = +[]; 
console.log(typeof p) //=> number 
console.log(p) //=> 0

```

Again, 

```
var p = ![]; 
console.log(typeof p); //boolean
console.log(p); //false 

```

Again, 

```
var p =   !![];
console.log(typeof p); // boolean
console.log(p); //true

```

Again, 

```
var p =   !+[];
console.log(typeof p);  //boolean
console.log(p);  //true

```

Now 

```
boolean true ==> 1
boolean false ==> 0 

```

So, 

```
var p =  (
   !+[] + 
   !![] + 
   !![] + 
   !![] + 
   []
 );
console.log(typeof p); //string 
console.log(p); // 4 

```

And 

```
var p = (
    !+[] + 
    !![] + 
    !![] + 
    !![] + 
    !![] + 
    !![] + 
    !![]
  );
console.log(typeof p); //number 
console.log(p);  // 7 

```

Finally: 

```
var p = +(
 (
   !+[] + 
   !![] + 
   !![] + 
   !![] + 
   []
 ) + 

  (
    !+[] + 
    !![] + 
    !![] + 
    !![] + 
    !![] + 
    !![] + 
    !![]
  )

);
console.log(typeof p); //Number
console.log(p); //47

```

You can write the same in php with array, boolean ( negation !) .
```
+[] -> 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

```