Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: missing variable name

I'm running JavaScript Lint on a project to check for common programming errors. I'm hitting this error:

SyntaxError: missing variable name

On this line:

var char, font;

From Googling, I've found that that error is shown when a reserved word is used as a variable name; but judging by MDN's list, neither char nor font is reserved.

What is the problem here?

like image 604
Danny Beckett Avatar asked Aug 15 '13 03:08

Danny Beckett


People also ask

What happens if you misspell a variable name in Javascript?

If a reference to a local variable is accidentally misspelled, it will be interpreted as a reference to an implicitly declared global variable, which may indicate a bug. Even if this is intentional, it should be avoided as it makes the code hard to read.

Which variable name is not allowed?

Variable name may not start with a digit or underscore, and may not end with an underscore.


2 Answers

Never mind, I found the answer by reading What is the 'char' keyword used for?.

Apparently char was reserved in ECMA 3, but removed as a reserved keyword in ECMA 5.

I've renamed my var now, to prevent any potential issues arising with old implementations.

like image 57
Danny Beckett Avatar answered Sep 18 '22 17:09

Danny Beckett


According to http://www.quackit.com/javascript/javascript_reserved_words.cfm

char is a keyword reserved by JavaScript.

I think font is fine.

like image 33
Andrew Avatar answered Sep 21 '22 17:09

Andrew