-
Out of retirement and back into Javascript
Numbers and strings (text)
In really basic Javascript if you set a variable equal to a number, you need to make sure the number is not inside brackets (” “).
This could cause the following problem:
x=5+5;
x=”5”+”5”
If you gave the order to: document.write(x); in the first example it would equal 10 in the second it would equal 55.
There’s actually a rule here if you add a number to a string the result will always be a string. so:
5 + “5” will equal 55 as well.
Posted on July 26, 2009
blog comments powered by Disqus