0

Plz explain

Var str=“abc”; Var arr =[1,2,3]; str.length =2; are.length=2; Console.log(str.length +arr.length); Why answer is 5 not 6

14th Nov 2018, 11:24 PM
Lailuma Norani
Lailuma Norani - avatar
2 Respuestas
+ 1
In javascript string are immutable so str.length=2 dont have any effect But array is mutable when you change its length it will change So because str is immutable its length stay at 3 And array length now is 2 3+2=5
15th Nov 2018, 12:20 AM
Taste
Taste - avatar
0
thank you so much u explained so well
15th Nov 2018, 12:27 AM
Lailuma Norani
Lailuma Norani - avatar