Weird behavior in this simple javascript snippet, can someone explain
whats going on?
Here is the jsfiddle
The full code:
function foo1(){
return {msg: "hello1"};
}
function foo2(){
return
{msg: "hello2"}
}
// output = "foo1 = {"msg":"hello1"}"
console.log('foo1 = ' , JSON.stringify(foo1()));
//output = " foo2 = undefined "
console.log('foo2 = ' , JSON.stringify(foo2()));
The difference between the two is that in foo2, the {msg: 'hello'} is in
its own new line. I was expecting the parser to ignore whitespaces?
No comments:
Post a Comment