Skip to content

Instantly share code, notes, and snippets.

@lc512k
Forked from anonymous/index.html
Last active October 7, 2015 12:13
Show Gist options
  • Save lc512k/1a28ea35b6a4f4de6ed3 to your computer and use it in GitHub Desktop.
Save lc512k/1a28ea35b6a4f4de6ed3 to your computer and use it in GitHub Desktop.
Value equality with coercion. Edge cases.
var testStr = function () {
var a = "5";
var b = "44";
console.log("num str", a > b); // true, lex comparison
};
testStr();
var testNaN = function () {
var a = 6;
var b = "five"; // coerced to NaN, neither lesser non greater
console.log("6 > five", a > b);
console.log("6 < five", a < b);
console.log("6 == five", a == b);
};
testNaN();
var testArray = function () {
var a = [1];
var b = [1];
console.log('arrays', a == b); // false, obj references
};
testArray();
var testEmpty = function () {
var a = 0;
var b = []; //""
console.log('empty things', a == b); // true, both coerced to num when either is num
};
testEmpty();
var testBool = function () {
var a = "";
var b = false;
console.log('bools', a == b); // true, both coerced to bool when both bool
};
testBool();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment