0

an explaination about this JS code, please...

var one =[2,4]; var two =[1,3]; var set =one+two; //set=[2,41,3] alert (set.length); output >> 6 // ?!?

20th Dec 2019, 3:52 PM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar
2 ответов
+ 6
Oneill :D adding (also alerting using alert(obj)) objects envokes their toString() method. arrays are also objects in js. first array is converted to => "2,4" second converted to =>"1,3" on addition the strings are conactenated "2,41,3" final product is obviously a string not an array so obviously commas , will also be counted as charecters. printing length property of "2,41,3" string you get 6 🤝 edit{ see this post by everything.js : https://www.sololearn.com/post/161927/?ref=app }
20th Dec 2019, 4:12 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
thx guys. I understood. I forgotten the type value
20th Dec 2019, 4:18 PM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar