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

  • Home
  • SEARCH
  • 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 8097523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:47:22+00:00 2026-06-05T21:47:22+00:00

As an example am I allowed to use the same variable and parameter? What

  • 0

As an example am I allowed to use the same variable and parameter? What issues can I run into?

Sample code

function mytask(name,title){
            var name = name;
            var title = title;
            var showalert = ("Hi " + name + " your job title is " + title);
            console.log(showalert);
            return showalert;
        }

document.write(mytask("dan", "administrator"));
  • 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-05T21:47:25+00:00Added an answer on June 5, 2026 at 9:47 pm

    Well in javascript you can think that, scopes are defined my curly brackets: { And }, and inside a scope variables can be redefined, so look at:

    function x(){
      var name=3;
      var name=4;
      console.log(name); // output is: 4
    }
    x();
    

    But this is just half true, actually what happens is that the interpreter goes over the code, and moves all var statements to the beginning, while they’re assigned an undefined (and all arguments are defined and taken from stack), and then the code you wrote will run. So any var after the first is simply ignored. And the code you wrote is equal to:

    function mytask(name,title){
       var name = arguments[0];
       var title = arguments[1];
       name = name;
       title = title;
       var showalert = ("Hi " + name + " your job title is " + title);
       console.log(showalert);
       return showalert;
    }
    
    document.write(mytask("dan", "administrator"));
    

    So your re-deceleration, and assignment is redundant. Anyway – the scope is not changing, nothing else will differ.

    Edit

    The interpreter goes over your code, with executing anything, any var x = y; statement will split into var x = undefined; and x=y;. And the var x = undefined; will be moved to the top of the code. And the x=y; will be at the same place as the original statement. If you didn’t understand the stuff about the stack, don’t bother, that’s how compilers convert function calls to assembly – it’s worth knowing in case you have time; but not THE important thing here.

    Anyway – just after those changes, and maybe some optimizations are made, the resulting code is executed. This is not the code you wrote, but an equal one. What you pointed out in redefining the arguments is an edge case where this transformations become visible.

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

Sidebar

Related Questions

Am I allowed to re-use the same variable name in different for loops in
Why to restrict allowed usernames by different rules? For example why can't user have
Example: an Employee table with an optional DateOfBirth field can be normalized into two
Is it allowed to use <body onLoad=myfunc()> along with jQuery's document.ready() handlers? I can't
For example, suppose I had written my own class which allowed me to record
Like in the example below, what is allowed, how and why? class Shape {
Here's a very quick example for my problem: http://img19.imageshack.us/img19/3575/workertool.png (I'm not allowed to post
Simple question, how do I shorten a call/name without using defines. For example, I
I have next task: I need to load the same file into my web
I'm not allowed to use a struct with the in keyword, am I? For

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.