Variables in Javascript

For the fist time ever I can’t follow Ivan’s logic. I see that the two textToshow values both both result in outputs with corresponding text. What I don’t understand is what rule determines when the variable is activated. I don’t know if my question even makes sense, but if anyone could explain to me how the variable acts, it would be greatly appreciated. To articulate my question in another way - why does output of the variable show first? Thanks.

I see that in one case Ivan has created a variable of textToShow with some text, and then another textToShow function with some different text, and has written alert(textToShow) below both of these. So I understand that there are two textToShow functions and both show as outputs. But I don‘t understand why it is necessary to write variable before one of them. Furthermore, I wrote a program as follows in Atom:

var textToshow=“hello world”;
textToshow=“what’s up?”;

You can see that alert(textToShow) is only written below the one without variable written before it, but it still results in two text alerts as outputs. Aaaahhhh. I dont understand what the variable is and how it works.

I’m not sure where to post this question. In the chapter 1 reading assignment it mentions that to put a \ as a character in a string you must do \\ and the two will collapse into one \. It gives the example: “A newline character is written like “\n”.” can be expressed: “A newline character is written like \”\n\"."

This is SUPER unlear to me. From the reading I would assume that it should be expressed as: “A newline character is written like “\\n”.” Why is there also a \ in front and another \ after the n?!? NOT explained in the reading at all.

Someone please explain?

oh wait, I get it… So the \ before the quote inside the quote prevents the quote from ending the string. And the quote before the end quote inside the string prevents THAT from also ending the string, and then the real end quote happens to end the string at the very end.

question 7 of the variables quiz makes NO sense. The modulo operator yields the remainder of dividing the first by the second. So 4 % 2 is the remainder of 4/2 (which is 2.0) so since there’s no decimal remainder, the result is 0. So the quiz question is (10+22) % 3 which is 32 % 3 which is the remainder of 32 / 3 (which comes to 10.6666666). So the answer should be 6666666666 to infinity, not the correct answer shown as 2! What am I missing here??? Please clarify!?

okay, upon further research I figured it out. The explanation given in elegant javascript was not good. Super vague and led me to assume remainder meant the decimal value, which in the case of 314 % 100 == 14 would be 314/100 which is 3.14, taking the decimal value as an integer would be 14. So THAT’S confusing for sure. Why not just say the remaining amount after dividing up one number by the other number in whole number amounts. For example 27 % 8 yields 3 because 27 can only fit 4 “8’s” inside of it, with 3 left over (24 with 3 remaining). That is a much more clear explanation, I think. For what it’s worth… So the quiz question of (10+22) % 3 yielding 2 makes more sense now.