Javascript: false if expression continues execution if scope code

I am experiencing some kind of weird Javascript behavior.

Although the expression in the expression ifevaluates to false, my code inside if blockcontinues to execute.

Here is the code snippet:

if (view.leftCols !== null) {
    var leftCols = view.leftCols.split(',');

    for (var lc = 0; lc < leftCols.length; lc++) {
        var lcv = leftCols[lc].split(':');
        var lcol = lcv[0];

        Array.add(allCols, lcol);

        try {
            var lwidth = lcv[1] - MyWorkGrid.getColWidth(lcol);

            if (lcol === 'Edit') {
                if ($.browser.msie && parseInt($.browser.version) <= 8) {
                    lwidth = 23;
                }
            }

            // this if statement fails.
            if (lwidth > 0) {
                grid.SetWidth(lcol, lwidth);
            }
        } catch (e) {
        }

         grid.MoveCol(lcol, 0, 1, 1);
    }
}

Here is my screenshot of Firebug:

Firebug

Any ideas?

+5
source share
2 answers

Despite highlighting a line in Firebug, are you sure it really does? I saw this behavior in Firebug (and earlier versions of the Chrome debugger), where they sometimes highlighted a line of code as if they had attacked it without executing that line.

, - (, console.log("lwidth = " + lwidth); if, , . , Firebug / , .

+12

, . , ​​ .

 1*   var a=0;b=0;c=0;
 2*   if( false ){
 3>       a++;
 4>       b++;
 5*       c++;
 6>   }
 7>
 8*   console.log( a+b+c ); // will output 0;

Firebug 1 2, 5, a, b c, 0.

(p.s. .. 2013 )

-1

All Articles