Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
JavaScript
var name = "I";
var setd = name;

let say i input "I" to the system

so now i want to check
<pre lang="Javascript">
if(name=="I")
{var printname = "i'm"+name;
}


so i want my end result will be i'm name.
Posted
Updated 26-Jun-14 18:36pm
v2
Comments
SRS(The Coder) 26-Jun-14 2:52am    
What is the issue to achieve this,
can you please elaborate properly your question ?
Thanks7872 26-Jun-14 2:55am    
Why such requirement at the first place? I can't consider this even as homework.

No.
You can't do that - it's just silly.
There is no mechanism in javascript (or any other language) to get the name of a variable holding an instance as a string.

Besides, even if you could, why would you want to? all you are doing is making the code less readable since you need to know the name of the variable at compile time in order to write the code to get the name of the variable!
JavaScript
var nameOfVariable = GetName(name);
Why not just cut out the middle man:
JavaScript
var nameOfVariable = "name";
 
Share this answer
 
v2
You need to be a little more clearer I think in what it is you're attempting to solve.
Do you just wish to output a concatenated string, i.e. your string literal "I'm" and their input "I"?
I'm not sure what you wish to solve.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900