Radu Radu - 6 months ago 5
Javascript Question

Why is 1 == '1\n' true in Javascript?

The same goes for

(and probably others).

if (1 == '1\n') {
else {
console.log('Not Equal');


As said before if you compare number == string, it will automatically try to convert the string to a number. the \n and \t are simply whitespace characters and therefore ignored.

This and similar behaviour can be rather confusing leading to situations like this:

(Picture taken from: https://www.reddit.com/r/ProgrammerHumor/comments/3imr8q/javascript/)