i have found a bug in the firebug reassembly of javascript internal code from the command editor

7 views
Skip to first unread message

David Costa

unread,
Dec 5, 2014, 11:32:40 PM12/5/14
to fir...@googlegroups.com
hello, i was playing a bit with firebug and i was trying to do a quick thing in it and i have created the following code to find fibonacci numbers until 1million.

var x1=0;
var x2=1;
var x3;

console.log(x1);
while(x2<1000000){
  console.log(x2);
  x3=x1;
  x1=x2;
  x2=x3+x2;
  //console.log("--"+x2);
}

i created this code in command editor and what happened after running it and reviewing the code is that the last number is wrong, it stays outside of the inequality, it is greater.

And i have checked that using the same code in an html5 file with the markups it works fine.

I think it is some kind of parse or reassembly of the code, like the way there can be code put in a tree of symbols.
It means that code from inside the command editor box is work differently than from the current webpage...

I know dealing with an entire programming language with javascript is kinda buggy. and the web browser has to work flawlessly...

Hope i helped ;)

Sebastian Zartner

unread,
Dec 8, 2014, 5:15:06 AM12/8/14
to fir...@googlegroups.com
The Command Editor evaluates the code entered and outputs its result. So the last number listed in the output (1346269) is the value returned by your code.
So if you execute 1+1 into the Command Editor or Command Line, you'll get 2 as result.
You can verify that by logging your numbers using some styling:

var x1=0;
var x2=1;
var x3;

console.log(x1);
while(x2<1000000){
  console.log('%c' + x2, 'color: green;');
  x3=x1;
  x1=x2;
  x2=x3+x2;
}


By that the output of your code will be listed in green while the return value of the evaluation will still be shown in dark blue.

To avoid getting the last number simply put your calculation code into a function and call that function:

function fibonacci(x1, x2) {

  var x3;

  console.log(x1);
  while(x2<1000000){
    console.log(x2);
    x3=x1;
    x1=x2;
    x2=x3+x2;
  }
}

fibonacci(0, 1);

Then the last logged line will be undefined indicating that the evaluated code didn't return anything.

Sebastian
Reply all
Reply to author
Forward
0 new messages