I am trying to simply add 2 different kinds of string, number, array, object and try analyze result, and understanding JS V8 engine working with them:
<script>
var a = "Peter";
var b = "Martin";
var c = 5;
var d = 10;
var e = ["red", "green", "blue"];
var f = ["lily", "Lotus"];
var g = {name: "Peter", age: 29};
var h = {country: "USA", state: "New York", gender: "Male"};
console.log(a+b);
console.log(c+d);
console.log(e+f);
console.log(g+h);
var i = g+h;
console.log(i);
console.log(i[0]);
console.log(i[1]);
console.log(i[2]);
</script>
In the code above I can understand:
Case 1: adding 2 strings will result "String".
Case 2: adding 2 numbers will add to be a number.
My Question is:
Case 3: How the hell trying add 2 arrays returns a string, that 2 merging last of 1st and 1st of last array?
Case 4: How in world can I access of whatever thing that is produced by direct merging of 2 objects?
Bonus Question:
Also, someone said that while adding 2 objects I will get an array of 2 objects. While, alas I have added code with "i" to show you that its not the case friend. While doing so the JS V8 engine has returned a string writting in text "[object object][object object]"
Now, please tell for "Case 4", how to access the 2 objects of this array (as you said)?