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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#