JavaScript Code


JavaScript const – Uncaught SyntaxError: Identifier ‘PI’ has already been declared


JavaScript const – Uncaught SyntaxError: Identifier ‘PI’ has already been declared

This error occurs when we try to declare an identifier or variable the second time in the same scope.

const PI = 3.14159;
const PI = 3.1415926; //Uncaught SyntaxError: Identifier 'PI' has already been declared

Solution

constant variables cannot be redeclared. second statement in the above code must not be written in the same block-scope.

const PI = 3.14159;