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 7497075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:55:23+00:00 2026-05-29T18:55:23+00:00

Why does var spo = function(){ var qq = function(){}; } throw the error

  • 0

Why does

var spo = function(){
   var qq = function(){};
}

throw the error undefined is not a function when

var spo = function(){
   function qq(){};
}

does not?


More elaborate example throws the exact error: TypeError: undefined is not a function

node version v0.6.10 compiled on Ubuntu

spo = function(car){

        var q = 10;
        var s = 'fraggle';

        var qq = function(){
                console.log(s);
        }

        (function(){

                while(q){
                        console.log(q);
                        q--;
                }
                        qq.call();
                        car.call();
        })();


};


spo(function(){console.log('as intended');});
  • 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-05-29T18:55:25+00:00Added an answer on May 29, 2026 at 6:55 pm

    In this qq is assigned the function dynamically.

    var spo = function(){
       // qq is undefined here
       var qq = function(){};
       // qq is defined here
    }
    

    On the other hand, in this case, qq is defined as a function which is visible everywhere in spo

    var spo = function(){
       // qq is defined here
       function qq(){};
       // qq is defined here also
    }
    

    EDIT:
    In your updated code the actual problem is visible, no semi colon after function which results in a wrong statement like given below

    var qq = function(){}()(); // This is causing TypeError
    

    Put a semi colon after function.

    var qq = function(){
        console.log(s);
    };  // you missed this semi colon
    
    (function(){
    
         while(q){
             console.log(q);
             q--;
         }
         qq.call();
         car.call();
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JavaScript does funky automatic conversions with objects: var o = {toString: function() {return 40;
Why does this code always return 0? var possibleMatches = new Array(); $.getJSON('getInformation.php', function(data)
why does this only alert 1 ? function test() { var myobj = {
Why the following code does not increase the variable a for 1 ? var
This code works: $(contentDiv).fadeIn(slow); This does not: var elementName = 'contentDiv'; $(elementName).fadeIn(slow); No fade
Does anyone have an example of using the ImageSnapshot.captureBitmapData function with a rotation matrix?
This crashes: var grdMakes = Ext.extend(Ext.grid.Panel, { constructor: function(paConfig) { } } This does
I have a php ternary operator as follows that does not work: var newLoginTxt
Does anyone know how to write this var q = from c in customers
Why does Resharper want you to change most variables to var type instead of

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.