Using Chrome’s web inspector as a calculator

chromeEvery version of chrome comes with a built in JavaScript inspector(activated by pressing Shift+Ctrl+J ). This is basically a debugger for your web application. It has pretty much everything that a normal debugger has for other languages like C, Java. So in this post I will show you how to use this inspector as general purpose calculator.
Once you open the inspector click on console tab to get an interactive prompt with > symbol. This is a full featured JavaScript interpreter, So the possibility of playing with this prompt are endless. But lets constrain our self to using it as a basic calculator(In a future post I will demonstrate more advanced uses).

First, doing basic arithmetic operations as shown below

Next, lets try converting a number from decimal to different bases (that ‘var n’ statement is required). The ‘toString(base)’ method can be invoked on any number and it takes the parameter base to which the actual number should be converted. In the first case it is evident that I am converting from decimal to binary format, then to octal and hexadecimal.

Next, Converting from other bases to decimal. The ‘parseInt(string,base)’ method takes a number in string format and converts it to the specified base 

Next, Converting from one base to other is a two step process

  1. convert from <any> base to decimal using parseInt method
  2. convert from decimal to <any> other base

Taking it a step further, we can type any valid JavaScript program at the prompt. Hope this is the start of your JavaScript journey!!

Leave a comment

Leave a Reply