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

119
Views
Confusion about Javascript Hoisting

I thought I grasped the concept of hoisting, but the code below got me confused. How does it return 1? Will the second example() function be hoisted above the first one?

function example() {
  return 9;
}

console.log(example());

function example() {
  return 1;
}

If a function declaration is hoisted in a compilation phase and a function expression is executed in the execution phase. How come the code below returns 7? Is it simply due to example expression being declared first?

var example = function() {
  return 7;
}

console.log(example());

function example() {
  return 0;
}

Thank you in advance!

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

The reason why var example = function() is getting called instead of function example() is the order of hoisting.

Functions are hoisted first, then variable declarations, per ECMAScript 5, section 10.5 which specifies how hoisting happens.

Read more here: Order of hoisting in JavaScript

about 4 years ago · Santiago Gelvez 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!