0

Could someone please explain this JavaScript answer?

This was a question in a JavaScript challenge quiz: What is the output of this code? var name1 = "John"; var name2 = "Sebastian"; console.log(name1.length + "" + name2.length); I am thinking the answer would be 13...however the answer was 49. Why? Could someone please explain?

24th May 2017, 1:30 PM
Chris Peterkin
Chris Peterkin - avatar
3 odpowiedzi
0
Ah, I see. Thank you!
24th May 2017, 1:34 PM
Chris Peterkin
Chris Peterkin - avatar
0
john = 4 Sebastian = 9 as thy are string so 4+9 = 49 its just string function hope you get it
24th May 2017, 5:12 PM
Dhruv Saxena
Dhruv Saxena - avatar
- 2
it is using your value as a string and performing concatenation function
24th May 2017, 4:08 PM
Zeeshan Salam
Zeeshan Salam - avatar