troubleshooting Question

Question about JavaScript errMsg{} object

Avatar of stevefNYC
stevefNYC asked on
Web Languages and StandardsJavaScript
8 Comments1 Solution492 ViewsLast Modified:
Hi all,

Have a question about an authors intention here when returning an object's value back to the calling function:

var errMsg = {
    // Checks for when a specified field is required
    required: {
        msg: "This field is required.",
        test: function(obj,load) {
            // Make sure that something was not entered and that this
            // isn't on page load (showing 'field required' messages
            // would be annoying on page load)
            return obj.value || load || obj.value == obj.defaultValue;
        }
    },
      
    // Makes sure that the field s a valid email address
    email: {
        msg: "Not a valid email address.",
        test: function(obj) {
            // Make sure that something was entered and that it looks like
            // an email address
            return !obj.value ||
                /^[a-z0-9_+.-]+\@([a-z0-9-]+\.)+[a-z0-9]{2,4}$/i.test( obj.value );
        }
    },
</snip>

That's just part of the code, but as you can see, he's consistently using !obj.value... why would you want to return it in this fashion?
ASKER CERTIFIED SOLUTION
basicinstinct

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros