Categories
JavaScript Answers

How to Fix the ‘SyntaxError: missing = in const declaration’ Error in Our JavaScript App?

Spread the love

Sometimes, we may run into the ‘SyntaxError: missing = in const declaration’ when we’re developing JavaScript apps.

In this article, we’ll look at how to fix the ‘SyntaxError: missing = in const declaration’ when we’re developing JavaScript apps.

Fix the ‘SyntaxError: missing = in const declaration’ When Developing JavaScript Apps

To fix the ‘SyntaxError: missing = in const declaration’ when we’re developing JavaScript apps, we should make sure we assign a value to any variable that’s declared with const when they’re declared.

On Edge, the error message for this error is SyntaxError: Const must be initialized.

On Firefox, the error message for this error is SyntaxError: missing = in const declaration.

And on Chrome, the error message for this error is SyntaxError: Missing initializer in const declaration.

Therefore, the following code will throw the error:

const COLUMNS;

To fix this, we write:

const COLUMNS = 100;

However, we don’t have to assign a value to a variable declared with let when they’re declared, so:

let columns;

won’t throw the error.

Conclusion

To fix the ‘SyntaxError: missing = in const declaration’ when we’re developing JavaScript apps, we should make sure we assign a value to any variable that’s declared with const when they’re declared.

On Edge, the error message for this error is SyntaxError: Const must be initialized.

On Firefox, the error message for this error is SyntaxError: missing = in const declaration.

And on Chrome, the error message for this error is `SyntaxError: Missing initializer in const declaration.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *