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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:47:58+00:00 2026-06-12T20:47:58+00:00

I have a global variable i which I increment (see fiddle here ): (function

  • 0

I have a global variable i which I increment (see fiddle here):

(function increment() {
   i += 1;   
})();

i = 0;

​In Chrome, I get the error Uncaught ReferenceError: i is not defined.

Shouldn’t the variable i be hosted here, so that inside the function increment, the variable i is defined as undefined?

  • 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-12T20:47:59+00:00Added an answer on June 12, 2026 at 8:47 pm

    Variable declaration statements are hoisted. You have no declaration.

    A declaration statement uses var to declare the variable. Since you haven’t declared it, all you have is the assignment expression, which implicitly creates the global variable at the time of the expression evaluation.

    In other words, no formal declaration means no hoisting.


    Now let’s say you did formally declare it, allowing the variable declaration to be hoisted. The operation inside the IIFE would result in NaN, but would be overwritten by the later assignment of 0.

    This is because only the declaration is hoisted, not the assignment.

    // The 'var i' part below is actually happening up here.
    
    (function increment() {
       i += 1;   // "i" is declared, but not assigned. Result is NaN
    })();
    
    var i = 0; // declaration was hoisted, but the assignment still happens here
    
    console.log(i); // 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can we have a single global variable which can be manipulated by multiple forms
I have a global variable I called Y_VAL which is initialized to a value
Assume that I have a global variable user in application....like this: # GET /users.xml
I am developing a shared library(.so) and dll. I have a global variable which
I have a global variable which needs to be initialized when the store is
So lets say I have this global variable foo , which while my server
I have a global variable which was declared in a formula in the Report
I have this global variable which is used as counter which I want to
I have a global variable which is an instance of a class. This class
I have a global variable myval which is of String type. String[] Category={----SELECT----,BEVERAGES,BREAKFAST,LUNCH,DINNER,DESSERTS,APPETIZERS &

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.