AviG
AviG

Reputation: 392

On VS Code, why is it telling me at every colon in a config JS file that I semi-colon is expected?

I'm using VS Code on a JavaScript project, and on what I've cloned to my computer, I keep getting ';' expected.ts(1005) on things like:

{
"debug" : true,
"cache" : true,
"logo" : "/assets/images/white-logo.png",
.
.
.
}

I have already changed to line endings to be Linux LF, as my workplace wants it. What's going on here?

Upvotes: 0

Views: 897

Answers (3)

Nagnath Mungade
Nagnath Mungade

Reputation: 1009

We can use double quote for key value pair for json data.

{ "Your first name": "Your first name", "Your last name": "Your last name" }

Upvotes: 0

somebody
somebody

Reputation: 111

You don't indicate which line is "1005". But I think it might be helpful to understand that the semi-colon is a terminator, in (most) scripting. In the same way that a Period is used in a Sentence for "natural" (Spoken, latin-based) Languages.

For further clarification

In Perl

use strict;
use something-else;

Terminating a Routine, or Function (again, in Perl)

my $remote_host = $ENV{REMOTE_HOST};

I chose Perl for examples, as

  • It's a different Language
  • It's syntax, and structure is very similar to JavaScript

Upvotes: 1

computercarguy
computercarguy

Reputation: 2463

I don't have a way to test this right now, but I have a feeling it's because you are treating your object keys as strings. If you look at the link below, they shouldn't have quotes around the keys.

https://www.w3schools.com/js/js_objects.asp

So, your object should look like:

{
    debug : true,
    cache : true,
    logo : "/assets/images/white-logo.png",
    .
    .
    .
}

If this is just output of a JSON object and you are using VSCode to just view it, then just ignore the errors. JSON used by browsers and send through HTTP protocols will normally have the quotes around the keys. Your code, on the other hand, shouldn't.

If this isn't the case, please post more code examples so we can get a better feel for what's going on.

Upvotes: 0

Related Questions