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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:02:25+00:00 2026-05-30T22:02:25+00:00

I am not some one who has done alot in javascript. My background is

  • 0

I am not some one who has done alot in javascript. My background is in Java/C++. I am currently working on a project that is using alot of javascript however and I came across something that doesn’t make sense to me but hopefully some javascript guru out there can give me a nice logical explanation.

var noDefinition = undefined;
var emptyString = "";
var noDefinitionAndEmptyString = noDefinition + emptyString;

console.log("NoDefinition");
console.log(noDefinition);

console.log("EmptyString");
console.log(emptyString);

console.log("noDefinition+emptyString");
console.log(noDefinitionAndEmptyString);

console.log("************************");
if(noDefinition == undefined)
{
    console.log("No Definition is undefined");
}


if(emptyString == undefined)
{
    console.log("emptyString is undefined");
}

if(noDefinitionAndEmptyString == undefined)
{
    console.log("noDefiniton and emptyString is undefined");
}

The code above produces the following results in my console:
[INFO] NoDefinition
[INFO]
[INFO] EmptyString
[INFO]
[INFO] noDefinition+emptyString
[INFO] undefined
[INFO] ************
[INFO] No Definition is undefined

So as you can see when I output the variables noDefinition and emptyString to the console, it produces blank output. When I concatenate them the console will produce undefined. However if I then proceed to use an if statement and compare each of them to undefined. The only if that executes is the first one.

This occurs even though when put to a console the value just shows up blank. Also the concatenation which shows up as undefined in the console fails its compare against undefined and never executes. I am confused by this and I am hoping out there some one can give me an explanation about what is going on.

  • 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-30T22:02:26+00:00Added an answer on May 30, 2026 at 10:02 pm

    When you concatenate undefined with a string it becomes a string

    var foo = undefined;
    var bar = "";
    console.log(foo+bar, typeof(foo+bar));
    * output *
    undefined string
    

    ECMAScript Docs – http://www.ecmascript.org/docs.php
    Not sure but reading the doc on Page 141 you can find this

    15.5.1 The String Constructor Called as a Function

    When String is called as a function rather than as a constructor, it performs a type
    conversion.

    Which lets me to believe why concatenation of anything with a string outputs a string

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

Sidebar

Related Questions

I'm sure I'm not the only one who has tried to switch the latest
How do I copy some directory from one place to another (not file by
Has anyone done this or attempted to do this for a preexisting project? It
After the last project I've done using WebForms, I've decided to pass on using
I'm dealing with an Oracle DBA at the moment, who has sent me some
I know someone who has a one-man company developing applications in Delphi and Pascal.
This was not written by me; it was written by someone who passed it
Before someone said that I did not read I may say that I read
I'm having some trouble opening an existing blackberry eclipse project I have to work
I've been doing some web development work in PHP recently which has led me

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.