Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Why does the Javascript engine ignore the first error which prints a const variable before it's initialized?

I have this snippet of code:

4-scoping.js

const thisIsAConst = 50

const constObj = {}

constObj.a = 'a'

let thisIsALet = 51
thisIsALet = 50

let thisIsALet = 50 // errors!

When I run this file, it has an error:

SyntaxError: Identifier 'thisIsALet' has already been declared

I try to modify the file, add a print function to print out thisIsAConst at the top of the file:

4-scoping.js

console.log(thisIsAConst)

const thisIsAConst = 50

const constObj = {}

constObj.a = 'a'

let thisIsALet = 51
thisIsALet = 50

let thisIsALet = 50 // errors!

Why do I get the same error?

SyntaxError: Identifier 'thisIsALet' has already been declared

What I expect is

ReferenceError: Cannot access 'thisIsAConst' before initialization

Is it the way the JavaScript engine work?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

"Identifier has already been declared" is a SyntaxError, it is raised on the parsing stage, before the program even starts running. Reference and Type Errors are runtime errors and are raised during the run time.

If you comment out the second let in this example, you'll first see the output from the first line, and then the ReferenceError:

console.log('hi')

console.log(c)

const c = 50

let v
let v

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!