Why does ++[[]][+[]]+[+[]] return the string “10”? This is valid and returns the string "10" in JavaScript (more examples here): ++[[]][+[]]+[+[]] Why? What is happening here? Solution: If we split it up, the mess is equal to: ++[[]][+[]] + [+[]] In JavaScript, it is true that +[] === 0. + converts something into a number, and in this case it will come down to +"" or 0 (see specification details below). Therefore, we can simplify it (++ has precendence over +): ++[[]][0] + [0] Because [[]][0] means: get the first element from [[]], it is true that: [[]][0] returns the inner
undefined
ToString() equivalent in PHP How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string: $myText = $myVar . ''; Like the ToString() method in Java or .NET. Answer: Can use the casting operators: $myText = (string)$myVar; There are more details for string casting and conversion in the Strings section of the PHP manual, including special handling for booleans and nulls.
undefined
How to check if one string contains another substring in JavaScript? Usually, I would expect a String.contains() method, but there doesn't seem to be one. What is the reasonable way to check for this? Answer : Here is a list of current possibilities: 1. indexOf - (see bottom) 2. (ES6) includes - go to answer, or this answer var string = "foo", substring = "oo"; string.includes(substring); 3. search - go to answer var string = "foo", expr= "/oo/"; string.search(expr); 4. lodash includes - go to answer var string = "foo", substring = "oo";