Last active
January 21, 2018 21:58
-
-
Save tsouk/0d3498cb111b3e7099c57070fd2de171 to your computer and use it in GitHub Desktop.
Quirky JS
This file contains hidden or 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
var a = { | |
i: 1, | |
// toString: function () { | |
// return a.i++; | |
// } | |
valueOf: function () { | |
return a.i++; | |
} | |
// When using loose equality, due to type coersion, if one of the operands is of a different type than the other, the engine will attempt to convert one to the other. In the case of an object on the left and a number on the right, it will attempt to convert the object to a number by first calling valueOf if it is callable, and failing that, it will call toString | |
// every time one of these is called, i is being incemented. The == operator calls valueOf then toString | |
} | |
if ( a==1 && a==2 && a==3 ) { | |
console.log("Hello Quirky 1!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment