What is causing an "Uncaught SyntaxError: Unexpected token ." in my app?

Wilhelm

My app is throwing an Uncaught SyntaxError: Unexpected token . in the following files:

Uncaught SyntaxError: Unexpected token . Tweet.js:2
Uncaught SyntaxError: Unexpected token . Timeline.js:2
Uncaught SyntaxError: Unexpected token . TimelineView.js:2
Uncaught SyntaxError: Unexpected token . app.js:2

However, when I refer to the files, to checkout the lines in question, I see no errors:

Tweet.js:

var com = com || {}
, com.apress = com.apress || {}
, com.apress.model = com.apress.model || {}
, com.apress.model.Tweet = Backbone.Model.extend({});

Timeline.js:

var com = com || {}
, com.apress = com.apress || {}
, com.apress.collection = com.apress.collection || {}

[...]

TimelineView.js:

var com = com || {}
, com.apress = com.apress || {}
, com.apress.view = com.apress.view || {}

[...]

app.js:

var com = com || {}
, com.apress = com.apress || {}
, com.apress.view = com.apress.view || {}
, com.apress.view.TimelineView = Backbone.View.extend({
});

$(function() {
    var timelineView = new com.apress.view.TimelineView();
});

I consistently get these errors and resolve them without ever understanding how I resolved them. What causes Uncaught SyntaxError: Unexpected token . errors and how do I resolve the ones above?

Felix Kling

. is not a valid character in a variable name, so you can't do

var com.apress = ... ;

Instead of using a variable declaration statement with multiple declarations, you should have a single declaration and simple assignments:

var com = com || {};
com.apress = com.apress || {};
com.apress.view = com.apress.view || {};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Uncaught SyntaxError: Unexpected token =

Uncaught SyntaxError: Unexpected token :

Create-React-App build - "Uncaught SyntaxError: Unexpected token <"

Uncaught SyntaxError: Unexpected token <

Uncaught SyntaxError: Unexpected token & in javascript django app

Express res.redirect causing "Uncaught SyntaxError: Unexpected token <"

Heroku create-react-app deploy Uncaught SyntaxError: Unexpected token <

Uncaught SyntaxError: Unexpected token ')'

Uncaught SyntaxError: Unexpected token '&'

Uncaught SyntaxError: Unexpected token 'if'

Firebase deployed react app not working. Uncaught SyntaxError: Unexpected token '<'

What is causing “Uncaught SyntaxError: Unexpected token o” with $.parseJSON() and JSON.parse()

Uncaught SyntaxError: Unexpected token :

Uncaught SyntaxError: Unexpected token :

Uncaught SyntaxError: Unexpected token <

Uncaught SyntaxError: Unexpected token }

Why does my JSONP request give me Uncaught SyntaxError: Unexpected token < (less than)?

Uncaught SyntaxError: Unexpected token in Javascript

Lodash or any import causing Uncaught SyntaxError: Unexpected token import

Uncaught SyntaxError: "Unexpected token { "

uncaught syntaxerror; unexpected token <

Uncaught SyntaxError: Unexpected token '<'

Uncaught SyntaxError: Unexpected token '!'

Uncaught SyntaxError: Unexpected token '<' while deploying create react app to firebase hosting

--Expected token ':'-- in my VS Code, but --Uncaught SyntaxError: Unexpected token 'return'-- on my browser

Uncaught SyntaxError: unexpected token: string literal in javascript. I can't figure out what's wrong

Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at App.js:18:1 in console

Uncaught SyntaxError: Unexpected token '<' (at index.js:1:1) REACT APP

Uncaught SyntaxError: Unexpected token '<'