const a = 10 + '20';                 // the sum of integer and string values
const b = '20' + '20';                   // the sum of two string values
console.log(a, b);                       // returns "1020" , "2020" 
console.log(typeof(a, b));          // both are strings
$a = 10 + '20';                          // The sum of an integer and a string
$b = '1020' + '20';                        // The sum two strings
echo $a, "\n ", $b, "<br>";         // returns 30, 1040 
echo var_dump($a, $b);            // both are integers (int+str) (str+str)
/* When you try to perform math operations with strings in PHP, they are cast to approprite type. In this case to int. But you can cast integer back to string in the below example */
$integer = 10;
$stringIncrement = '20';
$result = $integer + $stringIncrement;
$result = (string) $result;
var_dump($result);
by Luka Khitaridze
2 years ago
PHP
JavaScript
String
Integer
0
Pro tip: use ```triple backticks around text``` to write in code fences