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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:21:46+00:00 2026-06-18T10:21:46+00:00

The var keyword in javascript causes a variable to be stored in the local

  • 0

The var keyword in javascript causes a variable to be stored in the local scope. Without var variables belong to the global scope. What about functions? It’s clear what happens when functions are declared like variables

var foo = function() {...}

but what scope does

function foo() {...} 

belong to?

EDIT:
I realized I didn’t ask quite the right question so as a follow up. In the outer most nesting is there a difference between the above two declarations and the following declaration?

foo = function() {...}
  • 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-18T10:21:47+00:00Added an answer on June 18, 2026 at 10:21 am

    It belongs to the current scope, always. For example:

    // global scope
    
    // foo is a global function
    function foo() {
    
        // bar is local to foo
        function bar() {
    
        }
    
    }
    

    Regarding your second question, this:

    foo = function() {...}
    

    is an anonymous function expression assigned to a global variable (unless you’re running is strict mode, then foo would be undefined). The difference between that and function foo() {} is that the latter is a function declaration (versus a variable declaration, which is assigned an anonymous function expression).

    You might be interested in this excellent article about function declarations and function expressions: Named function expressions demystified.

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

Sidebar

Related Questions

Possible Duplicate: C# 'var' keyword versus explicitly defined variables EDIT: For those who are
Without knowing i typed 'far' instead of 'var' by my mistake.I noticed the keyword
Possible Duplicate: JavaScript this keyword I am a bit confused about the callbacks used
I noticed something peculiar about the with keyword in javascript and the parent and
<script type=text/javascript> function addbutton() { var o = document.getElementsByTagName('li'); for(var i=0;i<o.length;i++) { var keyword=
Possible Duplicate: Why is it bad to make elements global variables in Javascript? In
This question is about a similar javascript scope problem that I asked yesterday .
I'm new to Javascript and I just discovered the property keyword for defining functions
Here is a portion of my code: var styles:String = .keyword{color: #ff0000;} .comment{color: #00ff00;};
Often I see a global object defined in javascript code to act as a

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.