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

294
Views
Why are functions run in the module script file not in the window object?

The script file embedded directly in the HTML file, the functions contained in the window object. We can check with the following code.

    for(let i in window)
    {
        if ((typeof window[i]).toString() === "function" && !window[i].toString().includes("[native code]"))
        {
            console.log(i);
            console.log(window[i]);
            console.log("\n\n");
        }
    }

enter image description here

But when I run a function indirectly by importing it from module why isn't it in there? This is my file structure.

 1. index.html
 2. script.js
 3. moduleScript.js
 4. ModuleScript
    - moduleScript01.js
    - moduleScript02.js

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Event Listener</title>
    <script src="moduleScript.js" type="module"></script>s
    <script src="script.js"></script>
</head>
<body>
    <script type="module" defer>
        import * as moduleScript from "./moduleScript.js";
        
        console.log(moduleScript.moduleScript01.Level01(1,2));
        console.log(moduleScript.moduleScript02.Level02(1,2, 3));
        console.log("\n\n");
        
        for(let i in window)
        {
            if ((typeof window[i]).toString() === "function" && !window[i].toString().includes("[native code]"))
            {
                console.log(i);
                console.log(window[i]);
                console.log("\n\n");
            }
        }
        
        
    </script>
</body>
</html>

script.js

function Level01 (a, b)
{
    return a + b;
}

function Level02 (a, b, c)
{
    return Level01(a,b) - c;
}

function Level03 (a, b)
{
    return  Level02(a,b, 1) * 5;
}

function print ()
{
    console.log("Hello world");
}

moduleScript.js

export * as moduleScript01 from "./ModuleScript/moduleScript01.js";
export * as moduleScript02 from "./ModuleScript/moduleScript02.js";

moduleScript01.js

function Level01 (a, b)
{
    return a + b;
}

export
{
    Level01
}

moduleScript02

function Level02 (a, b, c)
{
    return Level01(a,b) - c;
}

export
{
    Level02
}
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!