Is spacing required when writing bash scripts?

In this lesson, I wrote an if statement and ran it on the shell prompt, but it gives me an error that says, “…command not found” even though the result was displayed.

But when I include spaces after the opening square bracket and before the closing square bracket, the error goes away.

When writing bash scripts, is spacing required?