{"id":108,"date":"2008-05-22T23:56:14","date_gmt":"2008-05-22T18:26:14","guid":{"rendered":"http:\/\/www.bin-co.com\/blog\/?p=108"},"modified":"2008-05-22T23:56:14","modified_gmt":"2008-05-22T18:26:14","slug":"hello-script-for-javascript","status":"publish","type":"post","link":"https:\/\/www.bin-co.com\/blog\/2008\/05\/hello-script-for-javascript\/","title":{"rendered":"Hello Script For JavaScript"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.bin-co.com\/blog\/wp-content\/uploads\/2008\/05\/javascript_logo.jpg\" alt=\"Javascript Rhino Logo\" title=\"Javascript Logo\" width=\"230\" height=\"194\" class=\"alignnone size-full wp-image-109 intro\" align=\"right\" \/><\/p>\n<p class=\"intro\">The next language to get the <a href=\"http:\/\/www.bin-co.com\/blog\/2008\/03\/learning-a-new-programming-language-the-hello-world-method\/\">Hello Script<\/a> treatment is <a href=\"http:\/\/www.openjs.com\/\">JavaScript &#8211; my favorite language<\/a>. Before we go any further, here is the definitions for Hello Script and JavaScript &#8211; just to make sure that we are on the same page&#8230;<\/p>\n<dl>\n<dt>Hello Script<\/dt>\n<dd><strong class=\"highlight\">&#8216;Hello Script&#8217; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet<\/strong> when working with that language.<\/dd>\n<dt><a href=\"http:\/\/localhost\/Sites\/openjs\/openjs.com\/about.php#about-js\">JavaScript<\/a><\/dt>\n<dd>JavaScript is a <strong class=\"highlight\">client side scripting language<\/strong> that is used in browsers.<\/dd>\n<\/dl>\n<h2>Code<\/h2>\n<p>Warning: Do not run this code &#8211; you will get a lot of alerts. If you have firebug extension, uncomment the first line &#8211; then you can run the code.<\/p>\n<pre><code class=\"html\">\n&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Hello Script for JS&lt;\/title&gt;\n&lt;script type=\"text\/javascript\"&gt;\n\/\/alert=console.log;\nalert(\"Hello World\");\n\n\/\/ Variables, concatination\nvar name = 'Binny';\nvar year = 2008;\nalert(\"Hello, \" + name + \" - welcome to \" + year );\n\n\/\/If,else conditions\nif (year &gt; 2008) {\n\talert(\"Welcome to the future - yes, we have flying cars!\");\n}\nelse if(year &lt; 2008) {\n\talert(\"The past - please don't change anything. Don't step on any butterflies. And for the sake of all thats good and holy, stay away from your parents!\");\n}\nelse {\n\talert(\"Anything wrong with your time machine? You have not gone anywhere, kiddo.\");\n}\n\n\/\/ For loop\nfor(var i=0; i&lt;3; i++) {\n\talert(i + \") Hi there!\");\n}\n\n\/\/Numerical Array, While\nvar rules = [\n\t'Do no harm',\n\t'Obey',\n\t'Continue Living'\n];\nvar i = 0;\nwhile(i&lt;rules.length) {\n\talert(\"Rule \" + (i+1) + \" : \" + rules[i]);\n\ti++;\n}\n\n\/\/ Associated array, foreach\nvar associated = {\n\t'hello'\t:\t'world',\n\t'foo'\t:\t'bar',\n\t'lorem'\t:\t'ipsum'\n}\nfor(key in associated) {\n\talert(key + \" : \" + associated[key]);\n}\n\n\/\/ Using Join and Split\ncsv_values = \"hello,world,how,are,you\".split(\",\");\nalert(csv_values.join(\":\"));\n\n\/\/ Function, argument, return, call\nfunction hello(name) {\n\treturn \"Hello \" + name;\n}\nhello_string = hello(\"Binny\");\nalert(hello_string);\n\n\/\/ One for the OOP fanboys - Class, members, object and stuff.\nfunction Movie(name) { \/\/Constuctor\n\tthis.name = name;\n}\nMovie.prototype.rateMovie = function() {\n\tthis.rating = (this.name.length % 10) + 1; \/\/IMDBs rating algorithm. True story!\n}\n\t\nMovie.prototype.printMovieDetails = function() {\n\talert(\"Movie : \" + this.name + \"\\nRating : \" + this.rating);\n}\n\n\/\/Create the object\nncfom = new Movie(\"New Country for Old Men\"); \/\/It's a sequel!\nncfom.printMovieDetails();\n\n\/\/ Regular Expressions\nstring = \"Hello World\";\nif(string.match(\/^Hell\/)) alert(\"Yup - its evil\\n\");\nalert(string.replace(\/l([^l])\/g, \"$1\")); \/\/Remove an 'l' from both words. Should alert('Helo Word'\n\n\n\/**\n * Specialized code\n *\/\nwindow.onload = function() {\n\tvar ele = document.getElementById(\"div-element\");\n\talert(ele);\n\tele.innerHTML = \"Hello World\";\n\tele.onclick = function() {\n\t\talert(\"You Clicked?\");\n\t}\n\t\n\tdocument.getElementById(\"text\").value = \"Goodbye World\";\n}\n&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n\n&lt;div id=\"div-element\"&gt;&lt;\/div&gt;\n\n&lt;input type=\"text\" value=\"3\" id=\"text\" \/&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>The next language to get the Hello Script treatment is JavaScript &#8211; my favorite language. Before we go any further, here is the definitions for <a class=\"mh-excerpt-more\" href=\"https:\/\/www.bin-co.com\/blog\/2008\/05\/hello-script-for-javascript\/\" title=\"Hello Script For JavaScript\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,15,25,28,30],"tags":[80,137,155,245,289],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-browsers","category-javascript","category-scripts","category-tutorial","category-web-development","tag-code","tag-hello","tag-javascript","tag-script","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":0,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}