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

208
Views
Javascript var and function hoisting discrepancy

function test1(a = 1) {
  console.log(a);
  var a = 2;
  function a() {}
}
function test2(a = 1) {
  console.log(a);
  function a() {}
}
test1(); // console log  1
test2(); // console log  [Function: a]

According to the understanding of variable hoisting, the variable a in the first function has the same name as the function a, and finally the function a covers the variable a, and there is only the function a in the second function. The output result should be the same.So Why is the function default parameter valid in the test1 function but not in the test2 function?

about 4 years ago · Juan Pablo Isaza
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!