Skip to content

Instantly share code, notes, and snippets.

@black-black-cat
Last active March 2, 2016 03:06
Show Gist options
  • Save black-black-cat/a1fc7f7270a6559f54c7 to your computer and use it in GitHub Desktop.
Save black-black-cat/a1fc7f7270a6559f54c7 to your computer and use it in GitHub Desktop.
运算中的隐式转换
var a;
var b = a * 0; // -> NaN
// NaN == NaN -> false
// NaN === NaN -> false
// b == b -> false
if (b == b) {
console.log(b * 2 + "2" - 0 + 4);
} else {
// 通过 - 号将字符串拼接转换为算术运算
console.log(!b * 2 + "2" - 0 + 4); // -> 26
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment