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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:53:12+00:00 2026-06-09T14:53:12+00:00

In the following function: foo = function(a){ if (!a) a = Some value; //

  • 0

In the following function:

foo = function(a){
    if (!a) a = "Some value";
    // something done with a
    return a;
}

When “a” is not declared I want to assign a default value for use in the rest of the function, although “a” is a parameter name and not declared as “var a”, is it a private variable of this function? It does not seem to appear as a global var after execution of the function, is this a standard (i.e. consistent) possible use?

  • 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-09T14:53:14+00:00Added an answer on June 9, 2026 at 2:53 pm

    It’s a private variable within the function scope. it’s ‘invisible’ to the global scope.
    As for your code you better write like this

    foo = function(a){
        if (typeof a == "undefined") a = "Some value";
        // something done with a
        return a;
    }
    

    Because !a can be true for 0, an empty string '' or just null.

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

Sidebar

Related Questions

Given is the following example: class Foo(object): def __init__(self, value=0): self.value=value def __int__(self): return
Some programming language allow parameters have default value in function call or attributes in
Say I have the following function: foo <- function(x, y = min(m)) { m
Suppose you have the following function foo . When I'm running a for loop,
Let's say we have the following function: foo <- function(x) { line1 <- x
Given the following javascript: function foo(selectControl) { ... } and the following html: <select
Given the following function: def foo(a, b, c): pass How would one obtain a
Is there a way to get the following function declaration? public bool Foo<T>() where
I have the following code: <?php function foo($bar) { global $products; //$products = array();
Wouldn't the pointer returned by the following function be inaccessible? char *foo(int rc) {

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.