Related Topic

DOCTYPE

DOCTYPE (Document type) is used to tell browser about version of html. Doctype must define at the beginning of the document.

Doctype is to be define as <!doctype html> for HTML 5.

Definition
<!doctype html>
<html lang="en">
    <head>
        <title> Page Title</title>
    </head>
    <body>
    </body>
</html>

1. How to fix Uncaught SyntaxError: Unexpected token < ?

The Syntax error Uncaught SyntaxError: Unexpected token < is caused by following reasons :

  • File using in script tag return 404, mean browser trying to fetch javascript file which does not exist
  • Script tag supposed to have existing js file reference but provided another file
  • Also it can caused during ajax call expecting to receive response as defined in ajax url (ex: json) but return other format (ex. nomn json if requested for json)
Here is the example for more understanding

Example 1 : Expecting src url as javascript file but given html file path
<!doctype html>
<html lang="en">
    <head>
        <!-- Expecting src url as javascript file but given html file path -->
        <script src="index.html" ></script>
        <title> Page Title</title>
    </head>
    <body>
    </body>
</html>

2. Why exclamation mark is used in before doctype html?

To understand WHY let's first understand

what is markup declaration

According to markupdeclaration.org

Declarative markup is the practice of identifying what information in a document is, typically separate from how it should be processed or presented.
Therefore to declare about document it is used exclamation mark. Example 1 : To define any comment it define like <!-- comment --> Example 2: To define any Document type it used exclamation mark before doctype like <!doctype html>