I am learning Arrow Functions in Javascript. Impressed by the "Shorter functions" example or definition of arrow functions given on Mozilla's MDN page.
According to the page/example-
var a2 = a.map(function(s){ return s.length });
and
var a3 = a.map( s => s.length );
do the same job! and a2 & a3 store an array of lengths of strings of a
.
So, I took up an initiative to compare the two(a2
and a3
) and ended up getting the result as false (control goes to the else
clause).
Here is my code-
var a = [
"Helium",
"Argon",
"Neon",
"Xenon",
"Krypton",
"Radon"
];
var a2 = a.map(function(s){ return s.length });
var a3 = a.map( s => s.length );
if (a2 == a3)
{
console.log("equal");
}
else
{
console.log(a2+" unequal "+a3);
}
I am getting this as the output in the console-
Even though a2
is the same as a3
, why am I getting a falsified answer?