+ 1

Why this given below question's answer is 5 ?

var str = "abc"; var arr = [1,2,3]; str.length=2; arr.length=2; console.log(str.length + arr.length);

18th Jul 2020, 5:59 PM
ILLUMINATIE
ILLUMINATIE - avatar
2 RĂ©ponses
+ 3
You can change the length of an array value but not the string. Strings are immutable by design. You can't change them. With “abc” , the length will always remain 3. Then you changed arr length to 2. In total this gives 5.
18th Jul 2020, 6:37 PM
Gustavo Cantu
Gustavo Cantu - avatar
+ 2
Thank you friend!😃
18th Jul 2020, 6:39 PM
ILLUMINATIE
ILLUMINATIE - avatar