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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:04:45+00:00 2026-06-11T02:04:45+00:00

Curious bit of code here… var x = 5; function fn() { x =

  • 0

Curious bit of code here…

var x = 5;

function fn() {
    x = 10;
    return;
    function x() {}
}
fn();
alert(x);

Here’s the jsFiddle

Is function x() {} called at all after return ?
Why not alert 10?

  • 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-11T02:04:47+00:00Added an answer on June 11, 2026 at 2:04 am

    function x() {} is hoisted to the start of fn‘s scope, and this effectively makes x a local variable before x = 10; is evaluated.

    The function is not set to 10.

    Update: The sentence above is wrong. x is actually set to 10. var is not used to declare it, but even if it was, the last sentence in the quote below only refers to the declaration part of the name x, not its assignment to 10.

    From MDN (emphasis mine):

    function

    Three forms with different scope behavior:

    • declared:
      as a statement at the parent function top-level

      • behaves like a var binding that gets initialized to that function
      • initialization “hoists” to the very top of the parent function, above vars

    var

    • function-scoped
    • hoist to the top of its function
    • redeclarations of the same name in the same scope are no-ops
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble understanding this bit of code in java.util.Arrays in openjdk. I'm curious
I am a bit curious about how this works - if I have 5
I am a bit curious on how the merge info in Subversion is used,
Specifically curious if IIS 5.1 has a 64 bit version, but I'm guessing only
I'm curious about the alignment of uint32_t types on 64-bit platforms. The spec says
While there are multiple ways to reverse bit order in a byte, I'm curious
Curious, what happens when you return keyword this from a struct in C#? For
The Below code does not fail to compile but however at runtime it says
I'm refactoring a little bit of C# data access code from a previous developer
If I do the following in code for an 8-bit processor: typedef union {

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.