Skip to content

Instantly share code, notes, and snippets.

@noahlt
Last active November 6, 2021 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahlt/4c9331a46e8e5bf802558ee75643fe18 to your computer and use it in GitHub Desktop.
Save noahlt/4c9331a46e8e5bf802558ee75643fe18 to your computer and use it in GitHub Desktop.
Are variables of the same value but different types equal?
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
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