Why number() method is not working in this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
16th Jul 2021, 5:33 PM
ANIL JOSHI
ANIL JOSHI - avatar
5 Answers
+ 1
Number(a) +d
16th Jul 2021, 5:43 PM
Abhay
Abhay - avatar
+ 4
Write Number(a) +d . //a is a string here and d is a number , whenever javascript sees a number and a string it concatenates them instead of adding. When you do a+Number(d) you add a string(a) and a number (d) and yes d is already a number , no need to convert it to a Number again!
16th Jul 2021, 5:58 PM
Abhay
Abhay - avatar
+ 3
let e = Number(a) + d;
17th Jul 2021, 8:33 AM
Solo
Solo - avatar
0
Code not working
16th Jul 2021, 6:07 PM
ANIL JOSHI
ANIL JOSHI - avatar
0
But this is not working. It's behave like a string
17th Jul 2021, 4:42 AM
ANIL JOSHI
ANIL JOSHI - avatar