[英]SyntaxError: expected expression, got '<' - javascript
So I looked around stackoverflow
and i see that this may have been asked before but I cannot wrap my head around the error. 所以我环顾了
stackoverflow
,发现以前可能有人问过这个问题,但是我无法解决这个错误。
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">
In a *.js
file you don't put a <!doctype>
header on the first line. 在
*.js
文件中,不要在第一行上放置<!doctype>
标头。
Just start with your Javascript code or, at most, put a "use strict";
只是从您的Javascript代码开始,或者最多是
"use strict";
there. 那里。
For example this is a valid JS file: 例如,这是一个有效的JS文件:
"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
}());
As it actually says, the DOCTYPE
declaration is for HTML , not for JavaScript. 实际上,
DOCTYPE
声明是针对HTML的 ,而不是针对JavaScript的。
Simply do not write it. 根本不写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.