How to Build Robust Javascript Code

Blog / Software Development / How to Build Robust Javascript Code
8/31/2018 | Joel Stephens

One of our developers was recently working on a Sitefinity site (no we won't tell you who the client was) and found an interesting line of Javascript.  The webpage was built as a fairly standard form and one of the things it needed to do was be sure that the "Group Code" field wasn't blank.  We found this code in the validation area.  If you aren't a developer this reads like this

"If the group code is not empty or the group code is not empty or the group code is not empty or the group code is not empty or the group code is not empty or the group code is not empty then everything is okay."

 

if (groupCodeEntered == '' || groupCodeEntered == '' || groupCodeEntered == '' || groupCodeEntered == '' || groupCodeEntered == '' || groupCodeEntered == '')

 

Most people assume robust code is built by adding test cases, validation rule, using best practices or some other common method.  The developer that wrote this code went a slightly different path.