Does JavaScript expression assert("1" === 1)
gives PASS(TRUE)
back ?
Asked
Active
Viewed 59 times
-4

Martin Tournoij
- 26,737
- 24
- 105
- 146

user3697106
- 61
- 1
- 2
-
How can a question be true or false? – David Schwartz Aug 20 '14 at 13:02
-
Look [here](http://www.w3schools.com/js/js_comparisons.asp) for a list of how operators work in javascript – Callum Linington Aug 20 '14 at 13:04
-
1Why don't you try it? – Martin Tournoij Aug 20 '14 at 13:15
3 Answers
1
No, '===' means identical. "1" and 1 aren't identical because "1" is a string and 1 is a integer. Using '==' would return true.

Xanco
- 874
- 1
- 10
- 15
0
No it would return false
.
The reason for this is because ===
is an equality check without coercion therefore the types are not converted. This means, effectively what you are comparing is a String
to an Number
which obviously aren't the same thing.
See Does it matter which equals operator (== vs ===) I use in JavaScript comparisons? for more info on the use of ==
vs ===
.
-1
String "1" is not === to integer 1, so you're evaluating assert(false) which returns fail
.
("1"===1) = false
assert(false) => fail

ffflabs
- 17,166
- 5
- 51
- 77