Watch out for expressions involving numeric and string values with the + operator
in expressions involving numeric and string values with the + operator, JavaScript converts numeric values to strings.
For example, consider the following statements:
x = “The answer is ” + 42 // returns “The answer is 42”
y = 42 + ” is the answer” // returns “42 is the answer”
In statements involving other operators, JavaScript does not convert numeric values to strings. For example:
“37” - 7 // returns 30
“37” + 7 // returns 377
Written by Koen De Waele
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Development
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#