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

187
Views
Why is this IIFE returning error undefined?

Why is this returning: Uncaught ReferenceError: winConditions is not defined?

I'm returning winConditions in the function and then I run the function and then console.log(winConditions), why is it not working?

const gameBoard = (() => {
    
    

    const board = [null, null, null, null, null, null, null, null, null]

    let applyWinConditions = () => {  
        const winConditions = [[board[0], board[1], board[2]], [board[3], board[4], board[5]],
        [board[6], board[7], board[8]], [board[0], board[3], board[6]],
        [board[1], board[4], board[7]], [board[2], board[5], board[8]],
        [board[0], board[4], board[8]], [board[2], board[4], board[6]]];
        console.log("e")
        return {
            winConditions
        }
    };

    applyWinConditions();

    console.log(winConditions)

    return {
        applyWinConditions: applyWinConditions,
    }

})();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

it seems you are trying to log a variable that is out of scope.

winConditions is defined inside applyWinConditions, thus not available outside, for console.log to see it.

try something like this:

console.log("winConditions", applyWinConditions());

you should see the return of your function, where winConditions has the value you'd expect.

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!