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?

9th Jun 2021, 1:35 PM
Rohit Ahuja
Rohit Ahuja - avatar
2 Antworten
+ 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
9th Jun 2021, 2:04 PM
A͢J
A͢J - avatar
- 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
9th Jun 2021, 5:03 PM
visph
visph - avatar