Syntax error: unexpected token "-"

I am making a web application, and when I started writing code in JavaScript, I get this error:

Syntax error: unexpected token "-" javascript 

I am using Aptana Studio 3. I thought this was an Aptana problem, so I tried with Eclipse, but still got the same error. Eclipse shows me this error:

 Cannot return from outside a function or method. 

Here is my function:

 function www_ebest_eu_company_node_service_task-slot-info () { this.typeMarker = 'www_ebest_eu_company_node_service_task-slot-info'; this._endDateTime = null; this._number = null; this._orderId = null; this._startDateTime = null; this._taskId = null; this._taskStatus = null; } 

I have many functions like this, and for each of them I get the same error.

Does anyone have the same problem?

+4
source share
4 answers

www_ebest_eu_company_node_service_task-slot-info not a valid JavaScript identifier.

+6
source

You cannot use hyphens in JavaScript function names:

 function www_ebest_eu_company_node_service_task-slot-info () { // Should proabbly be function www_ebest_eu_company_node_service_task_slot_info () { //---------------------------------------------^^^^^^^^ 
+5
source

The hyphen "-" is not a valid character for naming variables or functions. A hyphen is used for arithmetic, subtraction, and not for naming variables. You can replace hyphens with underscores or go to CamelCase notation.

+3
source

Names of identifiers (functions, variables, etc.) do not allow dashes. Stay with underscores or camelCase.

+2
source

Source: https://habr.com/ru/post/1392209/


All Articles