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

139
Views
How can undefined be a function?

Can you explain how does work this code block?

(function() { function undefined(){}; undefined() })()

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

0

undefined is not a keyword, it is just an identifier.

In the global scope, undefined is read only.

In the scope of the IIFE you have, you can create a new undefined variable that masks the global one.


Don't do that. It confuses people trying to maintain the code.

about 4 years ago · Juan Pablo Isaza Report

0

(function() {
  function undefined() {
    alert('d')
  };
  undefined()

  alert(undefined)
})()

alert(undefined)

This works because you are naming the function undefined inside a function. This means, inside the function's local scope, undefined = the function. As you can see if you run the code snippet, outside the function's scope, undefined = undefined once again.

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!