Create a gist now

Instantly share code, notes, and snippets.

@cheeaun /ab.js
Created Sep 13, 2010

What would you like to do?
Javascript variable to return 'A' but 'B' when converted to string.
// Answer for
// 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'}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment