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

177
Views
in Javascript, is `let a;` ever any different to `let a=undefined;`

Are the statements:

let a;

and

let a=undefined;

ever any different? Do they always compile to the same code in node and/or the browser?

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

0

They are equivalent..

A variable defined by a LexicalBinding with an Initializer is assigned the value of its Initializer's AssignmentExpression when the LexicalBinding is evaluated, not when the variable is created. If a LexicalBinding in a let declaration does not have an Initializer the variable is assigned the value undefined when the LexicalBinding is evaluated.

Where initializing let runs either the step:

Perform ? InitializeReferencedBinding(lhs, undefined).

(in the case of LexicalBinding : BindingIdentifier), or the step

Perform ? InitializeReferencedBinding(lhs, value).

where value is what's on the right-hand side of the =.

I suppose one very strange situation where they could be different is if someone created another identifier named undefined, but in any remotely sensible code, that shouldn't be seen.

{
  const undefined = 5;
  let a = undefined;
  console.log(a);
}

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!