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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:42:52+00:00 2026-05-29T21:42:52+00:00

I am currently reading a book on Javascript by Pragmatic, and I’m confused about

  • 0

I am currently reading a book on Javascript by Pragmatic, and I’m confused about one thing. They have a section on how to make variables global, local, or private.

  1. What is the difference between local and private variables? Is there one?

  2. How does one make a variable global or local, They said something about putting ‘var =’ before it, but it was very vague.

  • 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-29T21:42:53+00:00Added an answer on May 29, 2026 at 9:42 pm
    1. None, People use “private” because they are mistaken and are meant to say “local”

    2. local variables are defined as

    var foo = "local";

    global variables are a properties of the global scope object (which is window in the browser)

    window.foo = "global";

    The fact you can do foo = "global"; without first declaring variable foo with var foo is a “bug”. This is fixed in ES5 strict mode.

    (function () { "use strict"; foo = 42; })()

    gives ReferenceError: foo is not defined

    Note that you can make variables global by declaring them in outer most scope

    var foo = "global";
    function bar() {
      var foo = "local";
    }
    

    It should be noted that you shouldn’t have any code in outer most scope, ever. You should be wrapping all your scope in anonymous functions so that you get “module level scope”. This means you have a per file based top level scope. This is part of the module pattern.

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

Sidebar

Related Questions

I am currently reading a book about ASP.NET and I am a bit confused
Currently reading quite a heavy WCF book. I have used it myself in production
I have started to learn about python and is currently reading through a script
I am currently reading a book about bit fiddling and the following formula appears:
I am currently reading the book Javascript: The Good Parts and was playing with
Currently I have listed down learning Unix/Shell Scripting and reading CLR Algo book as
I'm new in SQL Server development and I'm currently reading a book, the thing
I'm reading a book about AI and currently learning about pathfinding(currently doing the Dijkstra
I'm currently reading a book about ASP.NET MVC3 to learn working with this framework.
I'm currently reading the book Pro Asp.Net MVC Framework. In the book, the author

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.