1

So I looked around stackoverflow 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">
6
  • Is this line part of a JS file? Commented Apr 16, 2016 at 12:19
  • This line is not the culprit...But your JS is.... Commented Apr 16, 2016 at 12:20
  • @ gurvinder372 yes. Commented Apr 16, 2016 at 12:20
  • Somewhere your browser is expecting javascript but you're returning HTML. You should NEVER include DOCTYPE or any other HTML in an actual javascript file unless it's enclosed in a string like document.write('<span>abc</span>');. Commented Apr 16, 2016 at 12:20
  • Why are you putting HTML into your Javascript file? Commented Apr 16, 2016 at 12:20

2 Answers 2

3

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
}());
Sign up to request clarification or add additional context in comments.

Comments

1

As it actually says, the DOCTYPE declaration is for HTML, not for JavaScript.

Simply do not write it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.