answer: is there any difference in javascript? “6″ + 7 + 8 and 6 + 7 + “8″. concatenating string and numbers

last week i posted a question about the difference between the results of  ’6′+ 7 + 8 and 6 + 7 + ’8′ in javascript. the concatenation of string and number can be a little trick.

probably you know that numbers are converted to string when it’s being concatenated to a string. it’s a interesting feature. however, it’s important to have a good understanding about how this conversation works. So, unexpected results can be avoided.

the conversation occurs only when the first string is added. So,

'6' + 7 + 8
> 678

while:

6 + 7 + '8'
> 138

it’s also important to know that it doesn’t happen with other math operations, such as:

'6' + 3*3 + '7'
> 697

or:

'6' + 3-3 + '7'
> 607

Leave a comment

name*

email* (not published)

website