S.M_Emamian S.M_Emamian - 2 years ago 610
HTML Question

SyntaxError: expected expression, got '<' - javascript

So I looked around

and i see that this may have been asked before but I cannot wrap my head around the error.

I get this error :

SyntaxError: expected expression, got '<' // first line

but my first line there is no error :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

pid pid
Answer Source

In a *.js file you don't put a <!doctype> header on the first line.

Just start with your Javascript code or, at most, put a "use strict"; there.

For example this is a valid JS file:

"use strict";

var x = 0;

But it is recommended to not poison the global space, so you really should do something more like this:

var LIB = (function () {
  "use strict";

  // your code goes here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download