0
var arr = [1,2,3]; var str= "abc"; arr.length = 2; str.length = 2; console.log(arr.length + str.length);
Why the answer is 5 and not 4?
3 Respostas
+ 2
®●H!T @HUJ@
You can't change string length but you can change array length so String length will remain same.
So 3 + 2 = 5
- 1
var arr = [1,2,3];
var str= "abc";
arr.length = 2;
str.length = 2;
console.log(arr.length + str.length);
// Why the answer is 5 and not 4?
// add these lines at the end, it will be self explained:
console.log(""+arr); // 1,2
console.log(str); // abc