[icoFolderApps.png]Program files
[icoHelp.png] Help[icoJavascript.png] Javascript
 Javascript (20oct2010)
First of all: it has nothing to do with java, except the c-like syntax. javascript was born as a client side scripting language embedded in HTML pages: nowadays almost all browsers incorporate a javascript interpreter, as you can test by opening the following HTML files.
<!DOCTYPE html> <html> <head> <title>Javascript example</title> <meta charset="UTF-8"/> </head> <body> <h1>Javascript arrays</h1> <h2>Iteration</h2> <script type="text/javascript"> var a = [0.1, 0.2, 0.3, 0.4]; for(var i in a) document.write("a["+i+"] = "+a[i]+"<br/>"); </script> <h2>Stack methods</h2> <script type="text/javascript"> var x = new Array(); x.push("ciao"); x.push("vado"); x.push("e"); x.push("torno"); var y = x.slice(); // copy to y while(x.length>0) document.write(x.pop()+" "); </script> <h2>Queue methods</h2> <script type="text/javascript"> while(y.length>0) document.write(y.shift()+" "); </script> </body> </html>
<!DOCTYPE html> <html> <head> <title>Javascript example</title> <meta charset="UTF-8"/> </head> <body> <h1>Javascript regular expressions</h1> <p>Let&apos;s start with an arbitrary string:</p> <script type="text/javascript"> var s = "ciao, sono andata da mia zia"; document.write("<pre>"+s+"</pre>"); </script> <p> Now modify it replacing the occurrences of a regular expression: </p> <script type="text/javascript"> var s1 = s.replace(/([nt])a\b/gi,"$1o"); document.write("<pre>"+s1+"</pre>"); </script> <p> The regexp <code>/([nt])a\b/gi</code> matches every word tail composed by a 'n' or a 't' followed by a 'a'; the <code>String</code> function member <code>replace</code> substitutes the 'a' in those occurrences with a 'o'. </p> <p> Now if we have:</p> <script type="text/javascript"> var a = "Weighing 122 pounds and measuring only 77.8 inches long"; document.write("<pre>"+a+"</pre>"); </script> <p> And we want to surround all numbers with round brackets, we will replace every occurrence of <code>/([\d\.]+)/g</code>, obtaining: </p> <script type="text/javascript"> document.write("<pre>"+a.replace(/([\d\.]+)/g,"($1)")+"</pre>"); </script> </body> </html>
javascript is now standardized in the ISO/IEC 16262 specification, and its use is spreading outside the browser context.