public
Last active

Javascript variable to return 'A' but 'B' when converted to string.

  • Download Gist
ab.js
JavaScript
1 2 3 4
// Answer for http://twitter.com/DmitryBaranovsk/status/24339436227
// Question: #jsquiz var a = …; Define a, so those alerts will work like that: alert(a + ""); // alerts "A"; alert(a); // alerts "B";
 
var a={toString:function(){return 'B'},valueOf:function(){return 'A'}};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.