What's the difference between 33.7 and "33.7" in JavaScript?


#1

Question

What’s the difference between 33.7 and “33.7” in JavaScript?

Answer

33.7 is a number, you can perform operations such as 33.7 * 2 or 33.7 + 0.3. "33.7" is a string. Yes it might represent a number but the data is stored as a string, so "33.7" + 0.3 would give you "33.70.3", not 34. This is not what is intended and happens because JavaScript converts 0.3 into a string, "0.3", and then combines the strings "33.7" and "0.3".