Skip to content

No value exists in scope for the short property: 2 Fixes

  • by
  • 2 min read

Writing JavaScript code has gotten simpler over the years, but there are still a lot of seemingly random bugs and glitches that keep popping up from time to time. 

In this article, we’re talking about the “no value exists in scope for the short property” error, its causes and what you can do to fix the problem.


What causes this error?

Several issues can cause this error. However, the main cause is an incorrect object-key declaration.

Make sure that when adding a new key-value pair to the object, you use a colon (:) instead of the equal sign (=). This is because the equal sign is used to store numbers, while the colon is used to store strings. Since we’re dealing with objects here, we’ll be using strings; hence, the colon sign is required.

Some of the other most common ones include:

  • Improper object syntax
  • Keys and values aren’t separated properly
  • Objects don’t have proper keys assigned to them

Also read: What’s the difference between Java and Javascript?


How to fix this?

Here are two fixes you can try out. 

Check object declaration syntax

As mentioned before, this error can be triggered if objects aren’t declared and initialised with proper keys. When adding a new key-value pair to the object, use a colon (:) instead of the equal sign (=). Here’s how you properly assign keys to objects.

var options = {
  host: 'localhost',
  port: 8080,
  path: '/',
  method: 'POST'
 }

Declare values correctly

As an extension to the aforementioned solution, once you’ve assigned proper values to the declared objects, 

This means that instead of this

obj.Object1 = 'Value';

Write this

obj['Object 1 object'] = 'Value';

Also read: What is the unexpected reserved word await error in Javascript?

>