{"id":70121,"date":"2021-08-26T04:10:07","date_gmt":"2021-08-26T08:10:07","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/what-you-really-need-to-learn-in-javascript-13\/"},"modified":"2021-08-26T04:10:07","modified_gmt":"2021-08-26T08:10:07","slug":"what-you-really-need-to-learn-in-javascript-13","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=70121","title":{"rendered":"What you really need to learn in Javascript? #13"},"content":{"rendered":"<pre style='padding-left:5px;padding-right:5px'>What you really need to learn in Javascript? <br \/>1. Where you can place JavaScript codes? <br \/>Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep javascript codes in an external file, the codes will be re-usable from different web-pages2. Some basic programming: <br \/><br \/> <br \/> <br \/> document.write('<b>Hello World<\/b>'); <br \/> <br \/>This will only be displayed in javascript enabled browsers.<br \/> <br \/> document.write('<a href=\"script.htm\">Page Requiring Javascript<\/a>'); <br \/> <br \/>3. Variables and their scopes <br \/> <br \/>  var hello = 'Hello World'; <br \/>   document.write(hello);<br \/> <br \/>var mynum = 5; <br \/>var smokes = false; <br \/>var riches = null; <br \/>var today = new Date;<br \/> Example use of variables: <br \/> <br \/>  var questions = 'If you have any questions about this <br \/>     please <a href=\"mailto:me@myaddress.com\">email me<\/a>.'; <br \/> document.write(questions);<br \/> <br \/>Another block can refer to questions variables without reassigning the value<br \/> <br \/>    document.write(questions);<br \/> <br \/>variables declared within a function is recognized only withing that function. Variables declared outside of a function is recognized anywhere in the webpage within javascript code from the declaration place. <br \/>4. Operators <br \/>Assignment operators <br \/> <br \/> var rich = 5000; <br \/> var lotsOfMoney = 100000; <br \/>    rich = lotsOfMoney; <br \/>  document.write(rich);<br \/> <br \/>Arithmetic and concatenation operators <br \/>five = two + three; <br \/>profit = income - expenses; <br \/>income = sales * price;<br \/>payment = total \/ instalments; <br \/>option = randnum % choices; <br \/>b = ++a;<br \/>c = a++;<br \/>d = --a;<br \/>e = a--; <br \/>Combination of Operators like c\/c++ <br \/>joy += happiness; <br \/>price -= discount; <br \/>capital *= interest; <br \/>pie \/= slices;<br \/>options %= choice; <br \/>Example use:<br \/> <br \/>    var singlePrice = 8;<br \/>  var bulkPrice = singlePrice * 9;<br \/>  document.write('<p>Buy our Widgets $'<br \/> +singlePrice+' for one, $'+bulkPrice+' for ten<\/p>'); <br \/> <br \/>5. Comparing Variables, Logical statements <br \/> <br \/> var red = 5;<br \/>  var blue = 3;<br \/> var match = null;<br \/> if (red == blue) <br \/> {<br \/>     match = 'equal'; <br \/> } <br \/>    else <br \/> {<br \/>     match = 'unequal'; <br \/>   }<br \/> document.write(red + ' and ' + blue + ' are ' + match); <br \/> <br \/>Other comparison operators: <br \/>if (red &gt; blue)<br \/>if (red &gt;= blue)<br \/>if (red &lt; blue)<br \/>if (red &lt; = blue)<br \/>if (red != blue) <br \/>Combining more than one comparison <br \/>if ((red == blue) || (red == green)) <br \/> <br \/>    var red = 5;<br \/>  var blue = 3;<br \/> var green = 3;<br \/>    var match = null;<br \/>     if ((red == blue) &amp;&amp; (red == green)) <br \/> {<br \/>     match = 'equal';<br \/>  } <br \/>    else <br \/> {<br \/>     purple = 'unequal';<br \/>   }<br \/> document.write(red + ' and ' + blue + ' are ' + match);<br \/> <br \/>Comparison in short<br \/>red == blue ? match = 'equal' : match = 'unequal'; <br \/>instead of<br \/>if (red == blue) <br \/>{<br \/>    match = 'equal';<br \/>} <br \/>else <br \/>{<br \/>      match = 'unequal'; <br \/>}<br \/>Example Use:<br \/><br \/><br \/>    var discPrice = 25;<br \/>   var regPrice = 25;<br \/>    var discount = regPrice - discPrice;<br \/>  if (discount &gt; 0)<br \/>      document.write('<p>Save $'+discount+ ' off the normal price of $' +regPrice+ 'now only $'+discPrice+'.<\/p>');<br \/> else<br \/>      document.write('<p>Buy now at our regular cheap price of $' + regPrice+'.<\/p>' ); <br \/><br \/>6. Switch statement in Javascript, very similar to C\/C++\/Java<br \/>use switch instead of multiple if\/else if<br \/><br \/>  var red = 1;<br \/>  var result = null;<br \/>    switch (red) <br \/> {<br \/>     case 1: result = 'one'; break; <br \/>       case 2: result = 'two'; break;<br \/>        default: result = 'unknown';<br \/>  }<br \/> document.write(result);<br \/> <br \/>Example:<br \/> <br \/>   var message = 0;<br \/>  switch (message) <br \/> {<br \/>     case 1: document.write('Merry Christmas'); break;<br \/>     case 2: document.write('Happy New Year'); break; <br \/>     case 3: document.write('Happy Easter'); break;<br \/>        case 4: document.write('Happy Holidays'); break;<br \/>      default: document.write('Welcome');<br \/>   }<br \/> <br \/>7. Function <br \/>        Defining a function <br \/>function myCode() <br \/>{<br \/>   document.write('<b>Hello World<\/b>'); <br \/>} <br \/>calling a function<br \/>myCode()<br \/>Example:<br \/>function displayMessage() <br \/>{<br \/> switch (message) <br \/> {<br \/>     case 1: document.write('Merry Christmas'); break;<br \/>     case 2: document.write('Happy New Year'); break;<br \/>      case 3: document.write('Happy Easter'); break;<br \/>        case 4: document.write('Happy Holidays'); break;<br \/>      default: document.write('Welcome');<br \/>   }<br \/>}     <br \/>var message = 0;<br \/>displayMessage(); <br \/>parameter passing<br \/>function writeSentence(argument1,argument2) <br \/>{<br \/>   document.write('The '+argument1+' is '+argument2+'.<br \/>'); <br \/>} <br \/>var a = 'table';<br \/>var b = 'chair';<br \/>var c = 'red';<br \/>var d = 'blue';<br \/>writeSentence(a,c);<br \/>writeSentence(b,c);<br \/>b = 'other ' + b;<br \/>writeSentence(b,d); <br \/>writeSentence('table',b); \/\/passing the value directly<br \/>Example:<br \/>function displayMessage(m) <br \/>{<br \/>   switch (m) <br \/>   {<br \/>     case 1: document.write('Merry Christmas'); break;<br \/>     case 2: document.write('Happy New Year'); break;<br \/>      case 3: document.write('Happy Easter'); break;<br \/>        case 4: document.write('Happy Holidays'); break;<br \/>      default: document.write('Welcome');<br \/>   }<br \/>} <br \/>In Javascript functions can also return values <br \/>function validField(fld) <br \/>{<br \/>  if (fld == '') return false; <br \/> return true;<br \/>} <br \/>function validField(fld) <br \/>{<br \/>    return (fld != '');<br \/>} <br \/>How to receive returned values and process <br \/>document.write(myField + ' is ');<br \/>if (!validField(myField)) <br \/>{<br \/>    document.write('not '); <br \/>}<br \/>document.write('empty'); <br \/>8. Alert and confirm <br \/> alert('Alert Message');  <br \/>Will display a message box with the message. Very useful in debugging javascript applications. <br \/>use confirm(), when you need user agreement on an issue. like: <br \/>if (confirm('Select a button'))<br \/>{<br \/>   alert('You selected OK'); <br \/>}<br \/>else <br \/>{<br \/>   alert('You selected Cancel'); <br \/>}<br \/>9. comments <br \/>\/\/ Scrolling Ad Javascript<br \/>\/\/ copyright 3rd September 2004, by Stephen Chapman <br \/>\/\/ permission to use this Javascript on your web page is <br \/>\/\/ granted provided that all of the code in this script (including <br \/>\/\/ these comments) is used without any alteration <br \/>or<br \/>\/* Scrolling Ad Javascript<br \/>copyright 3rd September 2004, by Stephen Chapman<br \/>permission to use this Javascript on your web page is<br \/>granted provided that all of the code in this script (including<br \/>these comments) is used without any alteration *\/ <br \/><br \/>10. Debugging JavaScript<br \/>    Test in different browsers like IE, Mozilla, Firfox, Netscape <br \/>    Enable Javascript and script debugging<br \/>    Script debugging usually reside under tools menu under browsing or web development sub-options<br \/><br \/>            Using alert to check variable values or if you can reach to a particular point of your code<br \/>        use bookmarklets, these are small scripts that can be used as plug in into browsers to provide error information.<br \/>            Use firebug in firefox, also use error console under tools menu to debug javascript error.<br \/>        Visual interdev provides Javascript debugging you may also enable external debugging by such programs<br \/>        11. External javascript<br \/><br \/>You can place all of your javascript codes to an external file. and use the file scripts\/functions from any webpage. <br \/>You just need to provide a reference to that external file.<br \/>You can provide reference as follows:<br \/>&lt;script language=&quot;javascript&quot; type=&quot;text\/javascript&quot; <br \/>  src=\"hello.js\"&gt;<br \/> <br \/>Note:  do not include any  or  in the external file. <br \/>12.  Using  tag:  this tag may help you to provide some information to the visitors  <br \/>when javascript is disabled or not supported by the browsers.<br \/><br \/>  document.write('<b>Hello Javascript World<\/b>'); <br \/><br \/>Hello World Without Javascript <br \/><br \/>    This page uses Javascript. Your browser either<br \/>    doesn't support Javascript or you have it turned off.<br \/> To see this page as it is meant to appear please use<br \/>  a Javascript enabled browser.<br \/><br \/>13. Objects and properties in Javascript <br \/>var strlen = myField.length; <br \/>var str = mynum.toString(); <br \/>function theLetter(num) <br \/>{<br \/>  var str = 'abcdefghijklmnopqustuvwxyz';<br \/>   return str.substr(num-1,1);<br \/>}<br \/>document.write(theLetter(5)); <br \/>14. Arrays in Javascript <br \/>var myArray = new Array(); <br \/>var myArray = new Array('message one',<br \/>'message two','message three'); <br \/>document.write(myArray[0]); <br \/>myArray[3] = 'message four'; <br \/>function displayMessage(m) <br \/>{<br \/> var greeting = new Array('Welcome','Merry Christmas',<br \/> 'Happy New Year','Happy Easter','Happy Holidays');<br \/>    if (m  greeting.length) m = 0;<br \/>    document.write(greeting[m]); <br \/>} <br \/>15. Loops<br \/>for (var i=0; i&lt;10; i++) <br \/>{<br \/> document.write(i);<br \/>} <br \/>var x = 0;<br \/>while (x&lt;10) <br \/>{<br \/>   document.write(x); <br \/>   x++;<br \/>} <br \/>var x = 12;<br \/>do <br \/>{<br \/> document.write(x); <br \/>   x++;<br \/>} while (x&lt;10) <br \/>16. Date and Time in Javascript<br \/>\/\/current date<br \/>var myDate = new Date; <br \/>myDate.setDate(15);<br \/>myDate.setMonth(3); \/\/ January = 0<br \/>myDate.setFullYear(2006); <br \/>myDate.setDate(myDate.getDate()+7); <br \/><\/pre>\n<p>From: http:\/\/sitestree.com\/?p=4732<br \/> Categories:13<br \/>Tags:<br \/> Post Data:2011-02-12 19:58:06<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What you really need to learn in Javascript? 1. Where you can place JavaScript codes? Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep javascript codes in an external file, the codes will be re-usable from different web-pages2. Some basic programming: document.write(&#8216;Hello World&#8217;); This will only be &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=70121\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-70121","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":65784,"url":"http:\/\/bangla.sitestree.com\/?p=65784","url_meta":{"origin":70121,"position":0},"title":"Some JavaScript stuff that you need to know #JavaScript","author":"Author-Check- Article-or-Video","date":"July 14, 2021","format":false,"excerpt":"What you really need to learn in Javascript? 1. Where you can place JavaScript codes? Anywhere in the web-pages, ideally in the header section, or in an external file. If you keep javascript codes in an external file, the codes will be re-usable from different web-pages 2. Some basic programming:\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26499,"url":"http:\/\/bangla.sitestree.com\/?p=26499","url_meta":{"origin":70121,"position":1},"title":"JavaScript Code #Programming Code Examples #Javascript #JavaScript","author":"Author-Check- Article-or-Video","date":"April 26, 2021","format":false,"excerpt":"var browser=navigator.appName; var b_version=navigator.appVersion; <a href=\"http:\/\/www.justetc.net\" target=\"_blank\"> <img border=\"0\" alt=\"hello\" src=\"b_pink.gif\" id=\"b1\" width=\"26\" height=\"26\" onmouseover=\"mouseOver()\" onmouseout=\"mouseOut()\" \/> Place the following code under script tag\/in a javascript file function mouseOver() { document.getElementById(\"b1\").src =\"b_blue.gif\"; } function mouseOut() { document.getElementById(\"b1\").src =\"b_pink.gif\"; } <map name=\"planetmap\"> <area shape =\"rect\" coords =\"0,0,82,126\" onMouseOver=\"writeText('You are over the\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10564,"url":"http:\/\/bangla.sitestree.com\/?p=10564","url_meta":{"origin":70121,"position":2},"title":"JavaScript Code","author":"","date":"August 29, 2015","format":false,"excerpt":"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var browser=navigator.appName; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var b_version=navigator.appVersion; <a href=\"http:\/\/www.justetc.net\" target=\"_blank\"> <img border=\"0\" alt=\"hello\" src=\"b_pink.gif\" id=\"b1\" width=\"26\" height=\"26\" onmouseover=\"mouseOver()\" onmouseout=\"mouseOut()\" \/> Place the following code under script tag\/in a javascript file function mouseOver() { \u00a0\u00a0 document.getElementById(\"b1\").src =\"b_blue.gif\"; } function mouseOut() { \u00a0\u00a0 document.getElementById(\"b1\").src =\"b_pink.gif\"; } <map name=\"planetmap\"> <area shape =\"rect\" coords =\"0,0,82,126\"\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10548,"url":"http:\/\/bangla.sitestree.com\/?p=10548","url_meta":{"origin":70121,"position":3},"title":"Javascript : Miscellaneous Code","author":"","date":"August 29, 2015","format":false,"excerpt":"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var browser=navigator.appName; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var b_version=navigator.appVersion; <a href=\"http:\/\/www.justetc.net\" target=\"_blank\"> <img border=\"0\" alt=\"hello\" src=\"b_pink.gif\" id=\"b1\" width=\"26\" height=\"26\" onmouseover=\"mouseOver()\" onmouseout=\"mouseOut()\" \/> Place the following code under script tag\/in a javascript file function mouseOver() { \u00a0\u00a0 document.getElementById(\"b1\").src =\"b_blue.gif\"; } function mouseOut() { \u00a0\u00a0 document.getElementById(\"b1\").src =\"b_pink.gif\"; } <map name=\"planetmap\"> <area shape =\"rect\" coords =\"0,0,82,126\"\u2026","rel":"","context":"In &quot;Ajax&quot;","block_context":{"text":"Ajax","link":"http:\/\/bangla.sitestree.com\/?cat=1418"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27156,"url":"http:\/\/bangla.sitestree.com\/?p=27156","url_meta":{"origin":70121,"position":4},"title":"Javascript : Miscellaneous Code #Programming Code Examples #Java\/J2EE\/J2ME #Ajax","author":"Author-Check- Article-or-Video","date":"May 12, 2021","format":false,"excerpt":"var browser=navigator.appName; var b_version=navigator.appVersion; <a href=\"http:\/\/www.justetc.net\" target=\"_blank\"> <img border=\"0\" alt=\"hello\" src=\"b_pink.gif\" id=\"b1\" width=\"26\" height=\"26\" onmouseover=\"mouseOver()\" onmouseout=\"mouseOut()\" \/> Place the following code under script tag\/in a javascript file function mouseOver() { document.getElementById(\"b1\").src =\"b_blue.gif\"; } function mouseOut() { document.getElementById(\"b1\").src =\"b_pink.gif\"; } <map name=\"planetmap\"> <area shape =\"rect\" coords =\"0,0,82,126\" onMouseOver=\"writeText('You are over the\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70149,"url":"http:\/\/bangla.sitestree.com\/?p=70149","url_meta":{"origin":70121,"position":5},"title":"JavaScript Miscellaneous Topics #13","author":"Author-Check- Article-or-Video","date":"August 27, 2021","format":false,"excerpt":"JavaScript Miscellaneous Topics. Please check below. Detect browser name and version: var browser=navigator.appName; var b_version=navigator.appVersion; Other browser related: navigator.appCodeName, navigator.platform, navigator.platform , navigator.cookieEnabled , navigator.userAgent, navigator.appMinorVersion, navigator.cpuClass, navigator.onLine, navigator.browserLanguage, navigator.systemLanguage, navigator.userLanguage It's a good idea to use escape function for setting cookie values (if more than one word). Also, use\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"hello","src":"b_pink.gif","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70121"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70121\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70121"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}