0
var body = "jsonString=123";
var mybody = body.replace("jsonString=","");
console.log("mybody:"+mybody);
console.log("myhead:"+body.replace("jsonString=",""));

This this should give two equal outputs to console.log file but it doesnt!

Output:
mybody:
myhead:123

Can someone explain why variable mybody is blank? Shouldnt it be 123?

EDIT I am such a fool, there were some unrelated problems with my execution environment that led to this. It has nothing to do with javascript. Thanks for the help SO

5
  • 5
    That should work. Is that your actual code? Commented Mar 30, 2012 at 19:08
  • Works for me, the only thing I can think of is it's trying to add a string to the number 123, so you can convert mybody to a string like mybody.toString() Commented Mar 30, 2012 at 19:11
  • 1
    Where are you running this? I just copy and pasted your code into a node REPL console and I saw what you EXPECTED to see (i.e. mybody:123) Commented Mar 30, 2012 at 19:12
  • @JKirchartz But both follow the same form: str+str Commented Mar 30, 2012 at 19:12
  • im such a retard, can I delete this question after I give you guys points? Commented Mar 30, 2012 at 19:18

1 Answer 1

2

It is giving me the correct output per this jsFiddle

Results:

mybody:123
myhead:123
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.