'JavaScript escape characters, same strings but different representation in browser

I have two strings. One is constant and another comes from firebase firestore. both are the same strings.

First one is local string:

const str =
              "3\r\n4 9\r\n2 7 11 15\r\n5 4\r\n2 3 1 15 7\r\n4 31\r\n16 1 15 7";

And another is string from firebase firestore:

{
    str: "3\r\n4 9\r\n2 7 11 15\r\n5 4\r\n2 3 1 15 7\r\n4 31\r\n16 1 15 7",
}

When I try to compare these two I get false output to console:

console.log(str === docSnapshot.data().str); // output: false

When I log both strings to console I get this output.

For first one:

console.log(str);

**output-**
3
4 9
2 7 11 15
5 4
2 3 1 15 7
4 31
16 1 15 7

For firestore sting:

console.log(docSnapshot.data().str);

**output-**
3\r\n4 9\r\n2 7 11 15\r\n5 4\r\n2 3 1 15 7\r\n4 31\r\n16 1 15 7

    

Please help me understanding this. And how can I log firebase string to console same as first one?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source