Because "true"
is converted to NaN
, while true
is converted to 1
. So they differ.
Like you reported, both are converted to numbers, because at least true
can be (see Erik Reppen’s comment), and then compared.
More Related Contents:
- How to check whether a string contains a substring in JavaScript?
- When should I use double or single quotes in JavaScript?
- Strip HTML from Text JavaScript
- How to force JS to do math instead of putting two strings together [duplicate]
- Escaping HTML strings with jQuery
- Count the number of occurrences of a character in a string in Javascript
- Is there a built in way to convert a comma-separated string to an array?
- Converting an object to a string
- endsWith in JavaScript
- Why does JavaScript handle the plus and minus operators between strings and numbers differently?
- What’s the best way to convert a number to a string in JavaScript?
- Check whether an input string contains a number in javascript
- Escaping Strings in JavaScript
- Convert camelCaseText to Title Case Text
- How to create a date object from string in javascript [duplicate]
- How do I replace all occurrences of a string in JavaScript?
- How to check if character is a letter in Javascript?
- Using JavaScript to perform text matches with/without accented characters
- How does adding String with Integer work in JavaScript? [duplicate]
- Remove empty strings from array while keeping record Without Loop?
- Replace string in javascript array
- JavaScript – Replace all commas in a string [duplicate]
- Replacing accented characters with plain ascii ones [duplicate]
- Create a string of variable length, filled with a repeated character
- Convert JavaScript String to be all lowercase
- String split returns an array with more elements than expected (empty elements)
- Best way to parse HTML in Javascript
- Put quotes around a variable string in JavaScript
- Split a string, at every nth position, with JavaScript? [duplicate]
- Javascript – Replacing the escape character in a string literal