2
var t2 = "\tMohamed\rMazen \n \tof \rMastering\n\t\t\programming";
console.log(t2);

The output using JavaScript is:

   Mohamed
Mazen 
    of 
Mastering
        programming

Shouldn't it be:

Mazen mohamed
Mastering of 
                  programming ?
  • 1
    Does this answer your question? [What is a \r" and why would one use it with a \n?](https://stackoverflow.com/questions/10282314/what-is-a-r-and-why-would-one-use-it-with-a-n) – Lain Nov 05 '20 at 14:15
  • Why would a change in whitespace re-order the words in a sentence? – Jared Smith Nov 05 '20 at 14:17
  • 3
    @Jared Smith: The logic is not so wrong. If by definition `\r` goes to the start of the line, `Mohamed` should actually be last. Alas, that is not how it works. – JavaScript Nov 05 '20 at 14:20
  • 1
    @JavaScript Looks like a way to see it, just that pointers usually overwrite and do not append. So `\tMohamed\rMazen` would end up as `Mazenmed`, depending on `\t`. – Lain Nov 05 '20 at 14:46
  • On a typewriter the result would be similar to what you give in the question, depending on how many spaces the tab was creating (ie if there was room to put the whole word in, otherwise it would overwrite). It depends on what is interpreting the string. How would e.g. MS Excel interpret it? I think browsers tend to ignore \r, but would be interested to hear if it’s otherwise. – A Haworth Nov 05 '20 at 17:19

0 Answers0