This memo just crossed my desk, from the CTO of one of the companies for which I consult. Caveat coder. Looking at some of our JavaScript code it seems like the use of new Boolean() and new String() has been growing. This will get you into trouble. For example: var b1 = new Boolean(false);var b2 = false; if ( b1 ) { // How the heck did I get here if x is false? // Because Boolean ob This memo just crossed my desk, from the CTO of one of the companies for which I consult. Caveat coder. Looking at some of our JavaScript code it seems like the use of new Boolean() and new String() has been growing. This will get you into trouble. For example: var b1 = new Boolean(false); var b2 = false; if ( b1 ) { // How the heck did I get here if x is false? // Because Boolean objects are true in a logical context. } if ( b2 ) { // As expected, we don’t execute this code. } var s1 = new String(“”); var s2 = “”; if ( s1 ) { // An empty string is supposed to be logically false too! // But this is a String *object* so we get true. } if ( s2 ) { // We never run this code, which is correct. } There are almost no reasons to use the new operator to create a String, Boolean, or Number object, and plenty of reasons why you shouldn’t. If you put any of those into a Session variable it can cause strange errors as well. If you need to explicitly convert some type to another type, use its conversion operator: var str = String(num); var num = parseInt(string); Software Development