Someone sent me this email:
Why do both of these alert to false?
alert('a' == 'a');
alert('a' === 'a');
Here's a demo
The first a
of each is not actually a simple a
. If you position the cursor right after it and hit Backspace, you delete "something", and then it returns true
.
I copied your a
string, this is what I get when running this code:
$a='a';
var_dump($a);
string(4) "a"
See what's wrong here? The string length is 4.
Furthermore, this:
echo base64_encode($a);
..returns:
YeKAjA==
When, for a simple string with the letter a
, it should only be YQ==
.
The extra character is called a "ZERO WIDTH NON-JOINER".
Is this a trick? Did you generate those a's
with some special unicode magic? I deleted the a's
and re-typed them, and now both alerts show true
, as they should
Updated Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With