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

158
Views
Unable to understand IIFE and scope in Node.js

Consider the following code snippet below

(async () => {
    const app = express();
    let test = "test string";

    app.get('/numbers', (req, res) => {
        res.send(test);
    }

    app.listen( 8000, () => {
      console.log( `server running http://localhost:8000`);
    });
)();

If I run the above code snippet, the server starts listening on localhost:8000.

How is that working?
How am I able to access test variable in my get method? Wouldn't the test variable be destroyed once the topmost function has finished executing?

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!