Why is number + string a string in javascript?
Sort of trying out some quirks in javascript: First I did console.log("5" + 1); This prints 51, this is normal right, both number and string have a + operator, but since string is the first variable it will convert 1 to a string. Now when I did this: console.log(1 + "5") I expected output to be 6, as I thought it would convert string to a number. However, the magic output was 15. Could anyone more experienced in javascript brighten this up for me? Quoting ECMAScript spec The Addition operator ( + ) section : If Type(lprim) is String or Type(rprim) is String, then Return the String that is the