Yes, like that.
The condition of the if statement is where classList.contains is used. to check that “video” is not there in the class list.
In this situation there are a few different ways to handle things.
You could check that the result is false:
if (video.classList.contains("video") === false) {
Or you could check that it’s not true:
if (video.classList.contains("video") !== true) {
Or you could invert the whole result by placing an exclamation mark at the start of things:
if (!video.classList.contains("video") === true) {
And because conditions of if statements are true when their condition is true, you can leave off the === true part.
if (!video.classList.contains("video")) {
Because that condition can be tricky to understand at first glance, it is also preferred to use a well-named variable to make things easier.
That way we could do:
const hasVideo = video.classList.contains("video");
if (hasVideo === false) {
or inverting the === operator:
const hasVideo = video.classList.contains("video");
if (hasVideo !== true) {
or inverting hasVideo:
const hasVideo = video.classList.contains("video");
if (!hasVideo === true) {
or inverting hasVideo without the === operator:
const hasVideo = video.classList.contains("video");
if (!hasVideo) {
All of those work, and they all have different subtleties about what they convey. In this case I prefer the last one. but you can use any one of those you pick.