Concatenation

What I did learn from this is that when any string characters are reached in a concatenation, JavaScript will then start doing strings versus numbers. In the last two examples above, I used the same addition of 1 + 2 + "4" and that came out to 34. But when I put a <br> formatting code in the very front of the write statement then it changed it to a string of 124.

I also learned that you must be very careful with quotation marks both remembering them and using them properly. I can see where you could get into trouble because in my examples I knew what I wanted to happen and if it did not happen that way I could look at it and see why not. But if I did not know what the result should be I may just get a result that was incorrect and not even know it.

In the above example I created three variables called yellow, blue, and orange. Each variable held the value of, the color name and the formatting to achieve that color as such: var yellow = "<b class=´yellow´>yellow</b>". I see that this is probably the easier way to do string variables that have lots of quotation marks going on because of my formatting needs. This way I am less likely to make a mistake because the document.write statement would then be a simple var + var + var with no quotations at all.

Here I thought I could out-fox JavaScript by making a variable = <br /> and add that variable to the numbers then I could have formatting with numbers, but alas that was not successful. I still get 124 because it is handling the variable as a string. Could this be more advanced due to the variable type?

Sure enough this variable is still recognized by JavaScript as a string so maybe I can do math on it and turn it into something other than a string?

YES! I subtracted a 0 from it and now it thinks it is a number. So if I add i to the other numbers will this work?

Heck no, now it is saying this variable i is Not a Number. Well that was fun trying...