Trying to use ! (not) operator to determine if class has been added.

Trying to use ! (not) operator to determine if class has been added.

I'm trying to determine if a class is added or not.

To determine if a class was added, I can do
if ($('#31').hasClass('item31required')){

But what I'm having a hard time getting right is checking to see the the class is NOT there.

would it be:

if !($('#31').hasClass('item31required')){ or if (!$('#31').hasClass('item31required')){

Thanks