syntaxerror: use of const in strict mode

The most common syntax error I see is when you try to build with strict mode. In this example, the const is used as an identifier for the type of object in your local scope, and you can’t use a const inside a const statement.

It’s because you can’t use a non-type (const) in a const statement. When the compiler finds a non-type, it will then think “Hey, I have an identifier with an underscore after it. I have to make an identifier with an underscore after it too.

When you use strict mode, you don’t get the type warnings, but it just becomes a lot more tedious to compile. Even though you might not realize it, the compiler will not actually warn you because the strict mode is a lot easier for the compiler to understand.

When you use a non-type const in a const statement, you need to create the constant. Because of the fact that consts don’t appear in strict mode, the compiler will never know what the constant actually is.

This makes programming code more tedious, but also less likely to cause bugs or memory leaks. Now that the compiler is smarter about the way you write code, you can use consts a lot more freely. You can also use consts in other parts of your code, for example in a switch statement.

consts are great because they allow you to access things without declaring them as local variables. In languages like C++, you need to declare a variable in the form of a type.

How about, for example, a variable named ‘name’ (a string) in the beginning of your code? That variable will be declared if you use it as an argument in the constructor of the class.

A more commonly used syntax error is to use const in strict mode without declaring it as a local variable. This can be done in the body of your code, but it’s usually just a plain statement.

This is one of those examples that’s so simple you can make it work in your head.

Leave a comment