Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:34:05+00:00 2026-06-11T07:34:05+00:00

The following code prints true. I can understand why ff.f is equal to undefined,

  • 0

The following code prints “true”. I can understand why ff.f is equal to undefined, but I don’t understand why console.log(“Hi”) is not executed inside ff.f when checking this value. Isn’t f immediately executed upon definition?

var ff = function(){
    var f = function(){
        console.log("Hi");
    }();
};

console.log(ff.f === undefined);

[Edit] I guess a better way to ask this question is “When does this f function inside ff get executed?”. I think it’s weird that ff.f’s value is “undefined” if it doesn’t get executed until ff gets executed. Shouldn’t it be the function instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:34:07+00:00Added an answer on June 11, 2026 at 7:34 am

    No, it is not – it is executed once it is evaluated – which in this case is when the parent function (ff) is executed.

    When is f executed

    Any IIFE will be executed once it is evaluated – any such expressions included inside of other functions will only evaluated once the function it is scoped to (wrapped in) executes:

    // Executed when the execution flow reaches this point
    // i.e. immediately after the script starts executing
    var outer = function() {
        console.log("Hello from outer");
    }();
    
    var wrapper = function() {
        // Executed when the flow reaches this point
        // which is only when the function `wrapper`
        // is executed - which it isn't, so this never fires.
        var inner = function() {
            console.log("Hello from inner");
        }();
    };
    

    Why ff.f is not a function

    JavaScript is function scoped but JavaScript does not provide any way to access a function’s inner scope (at least not, as far as I am aware). So when you try to access ff.f you are looking for a property named f on the function ff – and by default there is no such property. Even if you did:

    var ff = function () {
        ff.f = function() {
            console.log("Hello from f");
        }();
    };
    

    ff.f would still be undefined (because the IIFE does not return anything).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code prints out 10 . How can I make it print out
The following code, prints out Derived Base Base But I need every Derived object
The following code prints (when invoking MyMethod): 0 0 0 1 I would expect
The following code prints null once. class MyClass { private static MyClass myClass =
For example the following code prints { key: 'b' } function myFunc(key, value) {
Why is the following code prints xxY? Shouldn't local variables live in the scope
The following java code prints Hello World on my co-worker's computer: public void testJDBC()
if I compile (under G++) and run the following code it prints Foo::Foo(int). However
The following code with VS2010 prints 0 , contrary to my expectations: #include <complex>
I'm wondering why this code section prints out the following: print request.user.has_perm('bug_tracking.is_developer'): + str(request.user.has_perm('bug_tracking.is_developer'))

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.