[Fixed] Syntaxerror: invalid shorthand property initializer in Javascript

Syntaxerror: invalid shorthand property initializer error comes when we use equals operator rather than colon to separate key-values(properties) in object.

To resolve this issue, we need to use colon(:) rather than equals operator(=) between key and values of an object

Let’s see with the help of example:

Notice that we have used = between name and Bhutan.

To resolve this issue, use colon between key-value pair of an object.

To use new key-value property, you can use = sign.

Conclusion
To resolve Syntaxerror: invalid shorthand property initializer, use colon : to separate key-value pairs of object rather than equals operator(=).

That’s all about how to fix Syntaxerror: invalid shorthand property initializer.

Was this post helpful?

Leave a Reply

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