As someone who is naturally curious (and has no background in JS), I have decided to take the plunge into Typescript. However, I seem to have hit a roadblock. I am trying to compare two strings but want to make it easier by first converting them to lowercase. Below is the code snippet that I am using:
let bool: boolean = false;
let i = 0;
this.comparisons[++i] = " init bool " + " => " + bool;
bool = false;
if ("a" == "a") { bool = true };
this.comparisons[++i] = ' "a" == "a" ' + " => " + bool;
bool = false;
if ("a" == "b") { bool = true };
this.comparisons[++i] = ' "a" == "b" ' + " => " + bool;
bool = false;
if ("a" == "A") { bool = true };
this.comparisons[++i] = ' "a" == "A" ' + " => " + bool;
bool = false;
if ("a".toLowerCase == "A".toLowerCase) { bool = true };
this.comparisons[++i] = ' "a".toLowerCase == "A".toLowerCase ' + " => " + bool;
bool = false;
if ("a".toLowerCase == "B".toLowerCase) { bool = true };
this.comparisons[++i] = ' "a".toLowerCase == "B".toLowerCase ' + " => " + bool;
Upon execution, the output is as follows:
init bool => false
"a" == "a" => true
"a" == "b" => false
"a" == "A" => false
"a".toLowerCase == "A".toLowerCase => true
"a".toLowerCase == "B".toLowerCase => true
I am puzzled as to why the last comparison evaluates to true.
In my understanding, "a" == "b" should evaluate to false just like the third statement. What could be causing this unexpected behavior?