It checks to see if the element has the class, but it reverts the expression meaning it will run if the element doesn’t have a class. The ‘‘ is in-fact adding a space before the class so it doesn’t join another class. Using a bang (!) you can invert it’s meaning, so ...
Learn how to toggle a class by adding it when an element is clicked and removing it when clicked outside. Master click event handling in JavaScript.