Variable daclaration

In the Chore Door project, I noticed after step 50 or so that I declared this bunch of variables without using a declaration keyword:

doorImage1 = document.getElementById('door1');
doorImage2 = document.getElementById('door2');
doorImage3 = document.getElementById('door3');

However this has been working perfectly fine, not leading to any errors, as if this was Python or something…
What’s wrong here, why did this work? Did I just get lucky and some weird “okay, we’ll let it slide this time” mechanism in JS made it so that it could pretend those are variables?

Javascript is working as intended here. It has a feature that essentially allows you to not use a keyword to declare it, however this makes the variable a global variable. This can be seen in the outputs below.

door1 = `hello`

console.log(door1)
// prints 'hello'

const test = () => {
    door1 = `goodbye`
    console.log(door1)
// prints 'goodbye'
}

test()

console.log(door1)
// prints 'goodbye'

You have changed the value of door1 to goodbye in the function, as door1 is available in the global scope. Now if we remove the declaration outside the function, you would expect an error, however you get this.

const test = () => {
    door1 = `goodbye`
    console.log(door1)
    // prints 'goodbye'
}

test()

console.log(door1)
// prints 'goodbye'

So the declaration inside the function carried outside the function as it was globally declared. In the case of the doorImage variables in your case, I believe they want to be globally scoped so there’s no issue in this case. However generally you should add the declaration anyway. There’s no benefit as far as I’m aware to not declaring with ‘let’, and if you don’t have the keyword for a variable you want scoped to a single function, this can cause issues down the line.