Hello All,
i have read this javascript article, where an exmaple is shown , Please explain why below codes return different output due to changes the place of curly braces {
curly brace {
on new line
function test()
{
return
{ /* <----curly brace in new line*/
javascript : "fantastic"
};
}
var r = test();
try {
alert(r.javascript); // does this work...?
} catch (e) {
alert('no - it broke: ' + typeof r);
}
returns no - it broke: undefined
whereas
curly brace {
on same line
function test()
{
return { /* <----inline curly brace*/
javascript : "fantastic"
};
}
var r = test();
try {
alert(r.javascript); // does this work...?
} catch (e) {
alert('no - it broke: ' + typeof r);
}
returns fantastic
here is live exmpale beware of curly braces