Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript: Uncaught SyntaxError: Identifier 'count' has already been declared

Though the ‘count’ variable is not declared twice, I am getting this error.

Uncaught SyntaxError: Identifier ‘count’ has already been declared

Here is the code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="index.js"></script>
    <link rel="stylesheet" href="index.css">
    <title>Passenger Counter App</title>
</head>
<body>
    <h1>People Entered</h1>
    <h2 id="count-el">0</h2>
    <script src="index.js"></script>
</body>
</html>

JS

let count = 0
console.log(count)

OUTPUT

0
Uncaught SyntaxError: Identifier 'count' has already been declared (at index.js:1:1)

>Solution :

The index.js is imported twice(once in the head and then in the body). If you delete the one from the head then the error should go away.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading