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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:07:37+00:00 2026-05-19T10:07:37+00:00

First question var obj = function(){ var a = 0; this.b = 0; }

  • 0

First question

var obj = function(){  
    var a = 0;  
    this.b = 0; 
}

Is there any difference in behaviour of a and b?


Second question

var x = 'a';
var f1 = function(x){ alert(x) }
var f2 = new Function('alert('+x+')')

Is there any difference in behaviour of f1 and f2

  • 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-19T10:07:37+00:00Added an answer on May 19, 2026 at 10:07 am

    Question 1

    var obj = function() {
       var a = 0;
       this.b = 0;
    }
    

    Within the function, you’ll be able to access both variables, but in the case of

    var x = new obj();
    

    … you’ll be able to access x.b, but not x.a.

    Question 2

    As your question is written at the moment, it is a syntax error. The following will work:

    var x = 'a';
    var f1 = function(x){ alert(x) }
    var f2 = new Function('alert('+x+')')
    

    … but that would be the same thing as writing:

    var x = 'a';
    var f1 = function(x){ alert(x) }
    var f2 = new Function('alert(a)')
    

    The difference here is obvious. f1 disregards the global variable x and alerts whatever is passed to it, while f2 also disregards the global variable x, and tries to look for a global variable a. This is probably not what you’re trying to ask about.

    What you probably want is something like this:

    var x = 'a';
    var f1 = function(){ alert(x) }
    var f2 = new Function('alert(x)')
    

    … or this:

    var f1 = function(x){ alert(x) }
    var f2 = new Function('x', 'alert(x)')
    

    The difference between the two alternatives above is that the first always uses the global variable x, while the second never uses any global variable. The difference between f1 and f2, internally, in both examples, is none at all.

    These are two ways of generating the exact same result. The only reason you’d ever want to use the f2 approach would be when generating the code in some dynamic manner that require string input for its definition. In general, try to avoid this practice.

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

Sidebar

Related Questions

First of all there is a partial question regarding this, but it is not
this is my first question to stackoverflow so here it goes... I use cruise
this is my first question here so I hope I can articulate it well
This is my very first question so I am a bit nervous about it
This is my first question so please be patient :) Background: I'm implementing an
Greetings to all! This is my first question here on stackoverflow. I have a
first question here. I'm developing a program in C# (.NET 3.5) that displays files
First question on here so please be nice :) I know very little about
Here's my first question at SO. I have a internal application for my company
First shot at throwing a question on these boards so hopefully I can get

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.