After spending a frustrating hour trying to figure out why my JavaScript functions were not behaving as expected, I finally discovered the issue with some strategically placed alert() calls. It turns out that one function was meddling with the local variables of another function. In an attempt to better understand this unexpected behavior, I created a simple test script:
function first() {
msg = "1111";
second();
alert(msg);
}
function second() {
msg = "2222";
}
Upon calling first(), I anticipated receiving an alert displaying "1111", but instead, I was shown "2222". How could it be possible for second() to impact a local variable within first()? Is there something I'm overlooking or is this a potential bug?
This dilemma occurred while utilizing Firefox version 12.0.