Last active
November 6, 2021 22:40
-
-
Save noahlt/4c9331a46e8e5bf802558ee75643fe18 to your computer and use it in GitHub Desktop.
Are variables of the same value but different types equal?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef A = String; | |
typedef B = String; | |
void main() { | |
A a = "xxx"; | |
B b = "xxx"; | |
if (a == b) { | |
print("bad: variables with the same value are equal"); | |
} else { | |
print("excellent! variables with different types are not equal"); | |
} | |
} | |
// bad: variables with the same value are equal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type A = String; | |
type B = String; | |
let a: A = "xxx"; | |
let b: B = "xxx"; | |
if (a === b) { | |
console.log("bad: variables with the same value are equal"); | |
} else { | |
console.log("excellent! variables with different types are not equal"); | |
} | |
// bad: variables with the same value are equal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment