Monday 6 August 2007

Using internet browser as calculator

Most modern internet browsers support JavaScript. JavaScript may be executed in various ways, one of them - through pseudo url javascript:some_code. If this JavaScript code returns some value, the contents of all current web page is replaced with the result, converted to text (Safari on Windows v. 3.0.3 does not support this, apparently...).

Since JavaScript has means to perform mathematical operations, the internet browsers may be used as calculators. For example, to calculate 2+2 you could enter the following URL: javascript:2+2

Some more advanced math is possible, but it is not as straightforward, because advanced math functionality resides in JavaScript object Math. For example, to calculate number Pi, you should enter something like that: javascript:Math.PI , to calculate e10, you need the following line javascript:Math.exp(10), and so on.

P.S. And, speaking about browsers and calculators, don't forget about calculator built into google search engine. Just try googling for 2+2 ;)

No comments: